Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow minicolumn nesting #1558

Merged
merged 20 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion doc/format.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Re:VIEW フォーマットの文法について解説します。Re:VIEW フォーマットはアスキー社(現カドカワ)の EWB を基本としながら、一部に RD や各種 Wiki の文法を取り入れて簡素化しています。

このドキュメントは、Re:VIEW 3.0 に基づいています。
このドキュメントは、Re:VIEW 5.0 に基づいています。

## 段落

Expand Down Expand Up @@ -503,6 +503,19 @@ complexmatrixという識別子に基づく画像ファイルが貼り込まれ

内容には、空行で区切って複数の段落を記述可能です。

Re:VIEW 5.0 以降では、囲み記事に箇条書きや図表・リストを含めることもできます。

```
//note{

箇条書きを含むノートです。

1. 箇条書き1
2. 箇条書き2

//}
```

## 脚注

脚注は「`//footnote`」を使って記述します。
Expand Down
15 changes: 14 additions & 1 deletion doc/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The document is a brief guide for Re:VIEW markup syntax.

Re:VIEW is based on EWB of ASCII (now KADOKAWA), influenced RD and other Wiki system's syntax.

This document explains about the format of Re:VIEW 3.0.
This document explains about the format of Re:VIEW 5.0.


## Paragraph
Expand Down Expand Up @@ -532,6 +532,19 @@ Some block commands are used for short column.

The content is like paragraph; separated by empty lines.

From Re:VIEW 5.0, it is also possible to include itemize, figures and tables in short columns.

```
//note{

With ordered itemize.

1. item1
2. item2

//}
```

## Footnotes

You can use `//footnote` to write footnotes.
Expand Down
30 changes: 29 additions & 1 deletion lib/review/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def bind(compiler, chapter, location)

def builder_init_file
@sec_counter = SecCounter.new(5, @chapter)
@doc_status = {}
end
private :builder_init_file

Expand Down Expand Up @@ -542,9 +543,36 @@ def captionblock(_type, _lines, _caption, _specialstyle = nil)
CAPTION_TITLES.each do |name|
class_eval %Q(
def #{name}(lines, caption = nil)
check_nested_minicolumn
captionblock("#{name}", lines, caption)
end
), __FILE__, __LINE__ - 4

def #{name}_begin(caption = nil)
check_nested_minicolumn
@doc_status[:minicolumn] = '#{name}'
if caption
puts compile_inline(caption)
end
end

def #{name}_end
@doc_status[:minicolumn] = nil
end
), __FILE__, __LINE__ - 17
end

def check_nested_minicolumn
if @doc_status[:minicolumn]
error "#{@location}: nested mini-column is not allowed"
end
end

def in_minicolumn?
@doc_status[:minicolumn]
end

def minicolumn_block_name?(name)
CAPTION_TITLES.include?(name)
end

def graph(lines, id, command, caption = '')
Expand Down
74 changes: 63 additions & 11 deletions lib/review/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ def do_compile
f = LineInput.new(StringIO.new(@chapter.content))
@builder.bind(self, @chapter, Location.new(@chapter.basename, f))

## in minicolumn, such as note/info/alert...
@minicolumn_name = nil

tagged_section_init
while f.next?
case f.peek
Expand All @@ -274,20 +277,34 @@ def do_compile
warn 'Definition list starting with `:` is deprecated. It should start with ` : `.'
compile_dlist(f)
when %r{\A//\}}
f.gets
error 'block end seen but not opened'
if in_minicolumn?
_line = f.gets
compile_minicolumn_end
else
f.gets
error 'block end seen but not opened'
end
when %r{\A//[a-z]+}
# @command_name_stack.push(name) ## <- move into read_command() to use name
name, args, lines = read_command(f)
syntax = syntax_descriptor(name)
unless syntax
error "unknown command: //#{name}"
compile_unknown_command(args, lines)
line = f.peek
matched = line =~ %r|\A//([a-z]+)(:?\[.*\])?{\s*$|
if matched && minicolumn_block_name?($1)
line = f.gets
name = $1
args = parse_args(line.sub(%r{\A//[a-z]+}, '').rstrip.chomp('{'), name)
compile_minicolumn_begin(name, *args)
else
# @command_name_stack.push(name) ## <- move into read_command() to use name
name, args, lines = read_command(f)
syntax = syntax_descriptor(name)
unless syntax
error "unknown command: //#{name}"
compile_unknown_command(args, lines)
@command_name_stack.pop
next
end
compile_command(syntax, args, lines)
@command_name_stack.pop
next
end
compile_command(syntax, args, lines)
@command_name_stack.pop
when %r{\A//}
line = f.gets
warn "`//' seen but is not valid command: #{line.strip.inspect}"
Expand All @@ -306,6 +323,33 @@ def do_compile
close_all_tagged_section
end

def compile_minicolumn_begin(name, caption = nil)
mid = "#{name}_begin"
unless @builder.respond_to?(mid)
error "strategy does not support minicolumn: #{name}"
end

if @minicolumn_name
error "minicolumn cannot be nested: #{name}"
return
end
@minicolumn_name = name

@builder.__send__(mid, caption)
end

def compile_minicolumn_end
unless @minicolumn_name
error "minicolumn is not used: #{name}"
return
end
name = @minicolumn_name

mid = "#{name}_end"
@builder.__send__(mid)
@minicolumn_name = nil
end

def compile_headline(line)
@headline_indexs ||= [@chapter.number.to_i - 1]
m = /\A(=+)(?:\[(.+?)\])?(?:\{(.+?)\})?(.*)/.match(line)
Expand Down Expand Up @@ -619,6 +663,14 @@ def compile_inline(str)
@builder.nofunc_text(str)
end

def in_minicolumn?
@builder.in_minicolumn?
end

def minicolumn_block_name?(name)
@builder.minicolumn_block_name?(name)
end

def warn(msg)
@builder.warn msg
end
Expand Down
19 changes: 19 additions & 0 deletions lib/review/htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def sup_end(_level)
end

def captionblock(type, lines, caption)
check_nested_minicolumn
puts %Q(<div class="#{type}">)
if caption.present?
puts %Q(<p class="caption">#{compile_inline(caption)}</p>)
Expand Down Expand Up @@ -308,6 +309,24 @@ def note(lines, caption = nil)
captionblock('note', lines, caption)
end

CAPTION_TITLES.each do |name|
class_eval %Q(
def #{name}_begin(caption = nil)
check_nested_minicolumn
@doc_status[:minicolumn] = '#{name}'
puts %Q(<div class="#{name}">)
if caption.present?
puts %Q(<p class="caption">\#{compile_inline(caption)}</p>)
end
end

def #{name}_end
puts '</div>'
@doc_status[:minicolumn] = nil
end
), __FILE__, __LINE__ - 14
end

def ul_begin
puts '<ul>'
end
Expand Down
35 changes: 35 additions & 0 deletions lib/review/idgxmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -938,18 +938,22 @@ def captionblock(type, lines, caption, specialstyle = nil)
end

def note(lines, caption = nil)
check_nested_minicolumn
captionblock('note', lines, caption)
end

def memo(lines, caption = nil)
check_nested_minicolumn
captionblock('memo', lines, caption)
end

def tip(lines, caption = nil)
check_nested_minicolumn
captionblock('tip', lines, caption)
end

def info(lines, caption = nil)
check_nested_minicolumn
captionblock('info', lines, caption)
end

Expand All @@ -962,6 +966,7 @@ def best(lines, caption = nil)
end

def important(lines, caption = nil)
check_nested_minicolumn
captionblock('important', lines, caption)
end

Expand All @@ -970,10 +975,12 @@ def security(lines, caption = nil)
end

def caution(lines, caption = nil)
check_nested_minicolumn
captionblock('caution', lines, caption)
end

def warning(lines, caption = nil)
check_nested_minicolumn
captionblock('warning', lines, caption)
end

Expand All @@ -986,6 +993,7 @@ def link(lines, caption = nil)
end

def notice(lines, caption = nil)
check_nested_minicolumn
if caption
captionblock('notice-t', lines, caption, 'notice-title')
else
Expand Down Expand Up @@ -1021,6 +1029,33 @@ def expert(lines)
captionblock('expert', lines, nil)
end

CAPTION_TITLES.each do |name|
class_eval %Q(
def #{name}_begin(caption = nil)
check_nested_minicolumn
if '#{name}' == 'notice' && caption.present?
@doc_status[:minicolumn] = '#{name}-t'
print "<#{name}-t>"
else
@doc_status[:minicolumn] = '#{name}'
print "<#{name}>"
end
if caption.present?
puts %Q(<title aid:pstyle='#{name}-title'>\#{compile_inline(caption)}</title>)
end
end

def #{name}_end
if '#{name}' == 'notice' && @doc_status[:minicolumn] == 'notice-t'
print "</#{name}-t>"
else
print "</#{name}>"
end
@doc_status[:minicolumn] = nil
end
), __FILE__, __LINE__ - 23
end

def syntaxblock(type, lines, caption)
captionstr = nil
if caption.present?
Expand Down
46 changes: 46 additions & 0 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,53 @@ def column_end(_level)
@doc_status[:column] = nil
end

def common_block_begin(type, caption = nil)
check_nested_minicolumn
if @book.config.check_version('2', exception: false)
type = 'minicolumn'
end

@doc_status[:minicolumn] = type
print "\\begin{review#{type}}"

@doc_status[:caption] = true
if @book.config.check_version('2', exception: false)
puts
if caption.present?
puts "\\reviewminicolumntitle{#{compile_inline(caption)}}"
end
else
if caption.present?
print "[#{compile_inline(caption)}]"
end
puts
end
@doc_status[:caption] = nil
end

def common_block_end(type)
if @book.config.check_version('2', exception: false)
type = 'minicolumn'
end

puts "\\end{review#{type}}"
@doc_status[:minicolumn] = nil
end

CAPTION_TITLES.each do |name|
class_eval %Q(
def #{name}_begin(caption = nil)
common_block_begin('#{name}', caption)
end

def #{name}_end
common_block_end('#{name}')
end
), __FILE__, __LINE__ - 8
end

def captionblock(type, lines, caption)
check_nested_minicolumn
if @book.config.check_version('2', exception: false)
type = 'minicolumn'
end
Expand Down
Loading