arti_mark 0.1.beta3 → 0.1.beta5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +4 -4
 - data/README.md +108 -7
 - data/lib/arti_mark.rb +30 -35
 - data/lib/arti_mark/html/abstract_item_writer.rb +14 -0
 - data/lib/arti_mark/html/context.rb +100 -79
 - data/lib/arti_mark/html/generator.rb +51 -34
 - data/lib/arti_mark/html/header_writer.rb +3 -0
 - data/lib/arti_mark/html/pages.rb +56 -0
 - data/lib/arti_mark/html/paragraph_writer.rb +52 -0
 - data/lib/arti_mark/parser.kpeg +34 -6
 - data/lib/arti_mark/parser.kpeg.rb +1015 -128
 - data/lib/arti_mark/version.rb +1 -1
 - data/spec/arti_mark_spec.rb +338 -82
 - data/spec/created_files/.gitignore +1 -0
 - data/spec/fixture/test_src_ja.arti +3 -1
 - metadata +7 -18
 - data/lib/arti_mark/article_parser.rb +0 -12
 - data/lib/arti_mark/base_parser.rb +0 -26
 - data/lib/arti_mark/block_image_parser.rb +0 -27
 - data/lib/arti_mark/command_lexer.rb +0 -83
 - data/lib/arti_mark/common_block_parser.rb +0 -36
 - data/lib/arti_mark/definition_list_parser.rb +0 -23
 - data/lib/arti_mark/div_parser.rb +0 -12
 - data/lib/arti_mark/head_parser.rb +0 -20
 - data/lib/arti_mark/html/result.rb +0 -27
 - data/lib/arti_mark/list_parser.rb +0 -27
 - data/lib/arti_mark/ordered_list_parser.rb +0 -14
 - data/lib/arti_mark/paragraph_parser.rb +0 -30
 - data/lib/arti_mark/section_parser.rb +0 -12
 - data/lib/arti_mark/syntax.rb +0 -147
 - data/lib/arti_mark/universal_block_parser.rb +0 -10
 - data/lib/arti_mark/unordered_list_parser.rb +0 -14
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 8de4cdcdc26e89e9f5c20eb2347e382758f0be30
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 34278b22193013b08e276be60301768083e0177b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a6a59b4975fc9609e10b30fc517a9b52a22e2369fd9b30cd9dd8f8bc5b956ef44478d613772f6e05ca5d4caac0846ec7aa9db594b6fda9d1e70193a7b92ead78
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 17e7938d9294ea3e9f6d9c222676088474cdb09f13fcd071dcb43224ebf46b5354af2a332befa8102df94304643c5607a9792aa07cfa199ec7e4c45b0b8a36c5
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,12 +1,12 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # version 0. 
     | 
| 
      
 1 
     | 
    
         
            +
            # version 0.2beta3 (pre NoraText)
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
             * Totally rewrite using kpeg.
         
     | 
| 
       4 
     | 
    
         
            -
             *  
     | 
| 
       5 
     | 
    
         
            -
             *  
     | 
| 
      
 4 
     | 
    
         
            +
             * remove toc feature (for the old toc feature is so poor)
         
     | 
| 
      
 5 
     | 
    
         
            +
             * removed custom BlockParser. Instead of the feature, easy and powerful customization will be introduced in NoraText 0.2
         
     | 
| 
       6 
6 
     | 
    
         
             
             * markup change: alternate block notation starting with 'd{---' has removed
         
     | 
| 
       7 
7 
     | 
    
         
             
             * markup change: inline image notation is changed form [img(alt-text){src}] to [img(src, alt)]
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             * will change the name from ArtiMark to NoraText on next release 0. 
     | 
| 
      
 9 
     | 
    
         
            +
             * will change the name from ArtiMark to NoraText on next release 0.2rc1
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,8 +1,10 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # ArtiMark
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            ArtiMark is a simple text markup language. It is designed to create XHTML files for EPUB books.  
     | 
| 
      
 3 
     | 
    
         
            +
            ArtiMark is a simple text markup language. It is designed to create XHTML files for EPUB books. Its default mode is for Japanese text.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            **CAUTION This is very early alpha version, so it's not stable at all 
     | 
| 
      
 5 
     | 
    
         
            +
            **CAUTION This is very early alpha version, so it's not stable at all, even the markup syntax**
         
     | 
| 
      
 6 
     | 
    
         
            +
            In the next release,  the library name will change from ArtiMark to NoraMark.
         
     | 
| 
      
 7 
     | 
    
         
            +
            In NoraMark, the syntax will be more stable.
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
9 
     | 
    
         
             
            ## Installation
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
         @@ -22,16 +24,15 @@ Or install it yourself as: 
     | 
|
| 
       22 
24 
     | 
    
         | 
| 
       23 
25 
     | 
    
         
             
                require 'arti_mark'
         
     | 
| 
       24 
26 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                document = ArtiMark::Document. 
     | 
| 
       26 
     | 
    
         
            -
                document. 
     | 
| 
       27 
     | 
    
         
            -
                put document.result[0] # outputs 1st page of converted XHTML file
         
     | 
| 
      
 27 
     | 
    
         
            +
                document = ArtiMark::Document.parse(string_or_io)
         
     | 
| 
      
 28 
     | 
    
         
            +
                put document.html[0] # outputs 1st page of converted XHTML file
         
     | 
| 
       28 
29 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
            An example of markup text (text is in english, but the paragraph style is japanese)
         
     | 
| 
       30 
31 
     | 
    
         | 
| 
       31 
32 
     | 
    
         
             
                # line begins with # is a comment.
         
     | 
| 
       32 
33 
     | 
    
         
             
                # you don't need to indent artimark text.
         
     | 
| 
       33 
34 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                lang:  
     | 
| 
      
 35 
     | 
    
         
            +
                lang: ja
         
     | 
| 
       35 
36 
     | 
    
         
             
                title: test title
         
     | 
| 
       36 
37 
     | 
    
         
             
                stylesheets: css/normalize.css, css/main.css
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
         @@ -74,6 +75,106 @@ The converted XHTML file 
     | 
|
| 
       74 
75 
     | 
    
         
             
                </div>
         
     | 
| 
       75 
76 
     | 
    
         
             
                </div>
         
     | 
| 
       76 
77 
     | 
    
         
             
                </article>
         
     | 
| 
      
 78 
     | 
    
         
            +
                </body>
         
     | 
| 
      
 79 
     | 
    
         
            +
                </html>
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
            Another example of markup text in non-japanese (paragraph style is default)
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                # line begins with # is a comment.
         
     | 
| 
      
 84 
     | 
    
         
            +
                # you don't need to indent artimark text.
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                lang: en
         
     | 
| 
      
 87 
     | 
    
         
            +
                title: test title
         
     | 
| 
      
 88 
     | 
    
         
            +
                stylesheets: css/normalize.css, css/main.css
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
                art {
         
     | 
| 
      
 91 
     | 
    
         
            +
                    h1: header 1
         
     | 
| 
      
 92 
     | 
    
         
            +
                    article comes here.
         
     | 
| 
      
 93 
     | 
    
         
            +
                    linebreak will produce br.
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                    blank line will procude paragraph.
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                    d.column {
         
     | 
| 
      
 98 
     | 
    
         
            +
                        This block will produce div.column.
         
     | 
| 
      
 99 
     | 
    
         
            +
                        Inline commands like [link(http://github.com/skoji/arti_mark/){this}] and [s.strong{this}] is available.
         
     | 
| 
      
 100 
     | 
    
         
            +
                    }
         
     | 
| 
      
 101 
     | 
    
         
            +
                }
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
            The converted XHTML file
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                <?xml version="1.0" encoding="UTF-8"?>
         
     | 
| 
      
 106 
     | 
    
         
            +
                <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
         
     | 
| 
      
 107 
     | 
    
         
            +
                <head>
         
     | 
| 
      
 108 
     | 
    
         
            +
                <title> test title</title>
         
     | 
| 
      
 109 
     | 
    
         
            +
                <link rel="stylesheet" type="text/css" href="css/normalize.css" />
         
     | 
| 
      
 110 
     | 
    
         
            +
                <link rel="stylesheet" type="text/css" href="css/main.css" />
         
     | 
| 
      
 111 
     | 
    
         
            +
                </head>
         
     | 
| 
      
 112 
     | 
    
         
            +
                <body>
         
     | 
| 
      
 113 
     | 
    
         
            +
                <article>
         
     | 
| 
      
 114 
     | 
    
         
            +
                <h1>header 1</h1>
         
     | 
| 
      
 115 
     | 
    
         
            +
                <p>article comes here.<br />linebreak will produce paragraph.</p>
         
     | 
| 
      
 116 
     | 
    
         
            +
                <p>blank line will produce paragraph</p>
         
     | 
| 
      
 117 
     | 
    
         
            +
                <div class='column'>
         
     | 
| 
      
 118 
     | 
    
         
            +
                <p>This block will produce div.column.<br />Inline commands like <a href='http://github.com/skoji/arti_mark/'>this</a> and <span class='strong'>this</span> is available.</p>
         
     | 
| 
      
 119 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 120 
     | 
    
         
            +
                </article>
         
     | 
| 
      
 121 
     | 
    
         
            +
                </body>
         
     | 
| 
      
 122 
     | 
    
         
            +
                </html>
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
            Another example of markup text
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                # Markdown-ish heading will creates section
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                lang: ja
         
     | 
| 
      
 130 
     | 
    
         
            +
                title: test title
         
     | 
| 
      
 131 
     | 
    
         
            +
                stylesheets: css/normalize.css, css/main.css
         
     | 
| 
      
 132 
     | 
    
         
            +
                
         
     | 
| 
      
 133 
     | 
    
         
            +
                =: this is the first heading
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
                This line is in a section.
         
     | 
| 
      
 136 
     | 
    
         
            +
                This line is in a section.
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                ==: this is the second heading
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                This section is nested.
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                =: this is the third heading
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                will terminate lower level section
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
            The converted XHTML file
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
                <?xml version="1.0" encoding="UTF-8"?>
         
     | 
| 
      
 149 
     | 
    
         
            +
                <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
         
     | 
| 
      
 150 
     | 
    
         
            +
                <head>
         
     | 
| 
      
 151 
     | 
    
         
            +
                <title>test title</title>
         
     | 
| 
      
 152 
     | 
    
         
            +
                <link rel="stylesheet" type="text/css" href="css/normalize.css" />
         
     | 
| 
      
 153 
     | 
    
         
            +
                <link rel="stylesheet" type="text/css" href="css/main.css" />
         
     | 
| 
      
 154 
     | 
    
         
            +
                </head>
         
     | 
| 
      
 155 
     | 
    
         
            +
                <body>
         
     | 
| 
      
 156 
     | 
    
         
            +
                <section><h1>this is the first heading</h1>
         
     | 
| 
      
 157 
     | 
    
         
            +
                <div class='pgroup'><p>This line is in a section.</p>
         
     | 
| 
      
 158 
     | 
    
         
            +
                <p>This line is in a section.</p>
         
     | 
| 
      
 159 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 160 
     | 
    
         
            +
                <section><h2>this is the second heading</h2>
         
     | 
| 
      
 161 
     | 
    
         
            +
                <div class='pgroup'><p>This section is nested.</p>
         
     | 
| 
      
 162 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 163 
     | 
    
         
            +
                </section>
         
     | 
| 
      
 164 
     | 
    
         
            +
                </section>
         
     | 
| 
      
 165 
     | 
    
         
            +
                <section><h1>this is the third heading</h1>
         
     | 
| 
      
 166 
     | 
    
         
            +
                <div class='pgroup'><p>will terminate lower level section</p>
         
     | 
| 
      
 167 
     | 
    
         
            +
                </div>
         
     | 
| 
      
 168 
     | 
    
         
            +
                </section>
         
     | 
| 
      
 169 
     | 
    
         
            +
                </body>
         
     | 
| 
      
 170 
     | 
    
         
            +
                </html>    
         
     | 
| 
      
 171 
     | 
    
         
            +
                
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
       77 
178 
     | 
    
         | 
| 
       78 
179 
     | 
    
         
             
            In a near future version, you will be able to add custom commands.
         
     | 
| 
       79 
180 
     | 
    
         | 
    
        data/lib/arti_mark.rb
    CHANGED
    
    | 
         @@ -1,51 +1,46 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # -*- encoding: utf-8 -*-
         
     | 
| 
       2 
1 
     | 
    
         
             
            require "arti_mark/version"
         
     | 
| 
       3 
     | 
    
         
            -
            require "arti_mark/command_lexer"
         
     | 
| 
       4 
     | 
    
         
            -
            require "arti_mark/base_parser"
         
     | 
| 
       5 
     | 
    
         
            -
            require 'arti_mark/common_block_parser'
         
     | 
| 
       6 
     | 
    
         
            -
            require "arti_mark/paragraph_parser"
         
     | 
| 
       7 
     | 
    
         
            -
            require "arti_mark/div_parser"
         
     | 
| 
       8 
     | 
    
         
            -
            require "arti_mark/article_parser"
         
     | 
| 
       9 
     | 
    
         
            -
            require "arti_mark/section_parser"
         
     | 
| 
       10 
     | 
    
         
            -
            require "arti_mark/head_parser"
         
     | 
| 
       11 
     | 
    
         
            -
            require "arti_mark/block_image_parser"
         
     | 
| 
       12 
     | 
    
         
            -
            require "arti_mark/list_parser"
         
     | 
| 
       13 
     | 
    
         
            -
            require "arti_mark/ordered_list_parser"
         
     | 
| 
       14 
     | 
    
         
            -
            require "arti_mark/unordered_list_parser"
         
     | 
| 
       15 
     | 
    
         
            -
            require "arti_mark/definition_list_parser"
         
     | 
| 
       16 
     | 
    
         
            -
            require "arti_mark/universal_block_parser"
         
     | 
| 
       17 
     | 
    
         
            -
            require 'arti_mark/syntax'
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
2 
     | 
    
         
             
            require 'arti_mark/html/generator'
         
     | 
| 
       20 
3 
     | 
    
         
             
            require 'arti_mark/parser'
         
     | 
| 
       21 
4 
     | 
    
         | 
| 
       22 
5 
     | 
    
         
             
            module ArtiMark
         
     | 
| 
       23 
6 
     | 
    
         
             
              class Document
         
     | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                   
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
                private_class_method :new 
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def self.parse(string_or_io, param = {})
         
     | 
| 
      
 10 
     | 
    
         
            +
                  instance = new param
         
     | 
| 
      
 11 
     | 
    
         
            +
                  src = string_or_io.respond_to?(:read) ? string_or_io.read : string_or_io
         
     | 
| 
      
 12 
     | 
    
         
            +
                  yield instance if block_given?
         
     | 
| 
      
 13 
     | 
    
         
            +
                  instance.instance_eval do 
         
     | 
| 
      
 14 
     | 
    
         
            +
                    @preprocessors.each do
         
     | 
| 
      
 15 
     | 
    
         
            +
                      |pr|
         
     | 
| 
      
 16 
     | 
    
         
            +
                      src = pr.call(src)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    end
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @parser = Parser.new(src)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    if (!@parser.parse)
         
     | 
| 
      
 20 
     | 
    
         
            +
                      raise @parser.raise_error
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                  instance
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
       31 
25 
     | 
    
         | 
| 
       32 
26 
     | 
    
         
             
                def preprocessor(&block)
         
     | 
| 
       33 
27 
     | 
    
         
             
                  @preprocessors << block
         
     | 
| 
       34 
28 
     | 
    
         
             
                end
         
     | 
| 
       35 
29 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
                def  
     | 
| 
       37 
     | 
    
         
            -
                  @ 
     | 
| 
       38 
     | 
    
         
            -
                     
     | 
| 
       39 
     | 
    
         
            -
                    text = pr.call(text)
         
     | 
| 
       40 
     | 
    
         
            -
                  }
         
     | 
| 
       41 
     | 
    
         
            -
                  @parser = Parser.new(text)
         
     | 
| 
       42 
     | 
    
         
            -
                  if (!@parser.parse)
         
     | 
| 
       43 
     | 
    
         
            -
                    puts @parser.show_error
         
     | 
| 
       44 
     | 
    
         
            -
                    exit -1
         
     | 
| 
      
 30 
     | 
    
         
            +
                def html
         
     | 
| 
      
 31 
     | 
    
         
            +
                  if @html.nil?
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @html = @html_generator.convert(@parser.result)
         
     | 
| 
       45 
33 
     | 
    
         
             
                  end
         
     | 
| 
       46 
     | 
    
         
            -
                  @ 
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 34 
     | 
    
         
            +
                  @html
         
     | 
| 
       48 
35 
     | 
    
         
             
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
                
         
     | 
| 
      
 37 
     | 
    
         
            +
                def initialize(param = {})
         
     | 
| 
      
 38 
     | 
    
         
            +
                  @preprocessors = [
         
     | 
| 
      
 39 
     | 
    
         
            +
                                    Proc.new { |text| text.gsub(/\r?\n(\r?\n)+/, "\n\n") },
         
     | 
| 
      
 40 
     | 
    
         
            +
                                   ]
         
     | 
| 
      
 41 
     | 
    
         
            +
                  @html_generator = Html::Generator.new(param)
         
     | 
| 
      
 42 
     | 
    
         
            +
                end 
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
       49 
44 
     | 
    
         | 
| 
       50 
45 
     | 
    
         
             
              end
         
     | 
| 
       51 
46 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,98 +1,119 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module ArtiMark
         
     | 
| 
       2 
     | 
    
         
            -
            module Html
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                       
     | 
| 
       19 
     | 
    
         
            -
                         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
      
 2 
     | 
    
         
            +
              module Html
         
     | 
| 
      
 3 
     | 
    
         
            +
                class Context
         
     | 
| 
      
 4 
     | 
    
         
            +
                  attr_accessor :title, :head_inserters, :toc, :lang, :stylesheets, :enable_pgroup
         
     | 
| 
      
 5 
     | 
    
         
            +
                  def initialize(param = {})
         
     | 
| 
      
 6 
     | 
    
         
            +
                    @head_inserters = []
         
     | 
| 
      
 7 
     | 
    
         
            +
                    @toc = []
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @lang = param[:lang] || 'en'
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @title = param[:title] || 'ArtiMark generated document'
         
     | 
| 
      
 10 
     | 
    
         
            +
                    @stylesheets = param[:stylesheets] || []
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @stylesheets_alt = param[:stylesheets_alt] || []
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @enable_pgroup = param[:enable_pgroup] || true
         
     | 
| 
      
 13 
     | 
    
         
            +
                    self.paragraph_style= param[:paragraph_style]
         
     | 
| 
      
 14 
     | 
    
         
            +
                    @pages = Pages.new(param[:filename_base], param[:sequence_format])
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @block_delimiter_stack = []
         
     | 
| 
      
 16 
     | 
    
         
            +
                    head_inserter do
         
     | 
| 
      
 17 
     | 
    
         
            +
                      ret = ""
         
     | 
| 
      
 18 
     | 
    
         
            +
                      @stylesheets.each { |s|
         
     | 
| 
      
 19 
     | 
    
         
            +
                        if s.is_a? String
         
     | 
| 
      
 20 
     | 
    
         
            +
                          ret << "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{s}\" />\n"
         
     | 
| 
      
 21 
     | 
    
         
            +
                        elsif s.is_a? Array
         
     | 
| 
      
 22 
     | 
    
         
            +
                          ret << "<link rel=\"stylesheet\" type=\"text/css\" media=\"#{s[1]}\" href=\"#{s[0]}\" />\n"  
         
     | 
| 
      
 23 
     | 
    
         
            +
                        else
         
     | 
| 
      
 24 
     | 
    
         
            +
                          raise "Can't use #{s} as a stylesheet"
         
     | 
| 
      
 25 
     | 
    
         
            +
                        end
         
     | 
| 
      
 26 
     | 
    
         
            +
                      }
         
     | 
| 
      
 27 
     | 
    
         
            +
                      ret
         
     | 
| 
      
 28 
     | 
    
         
            +
                    end
         
     | 
| 
       27 
29 
     | 
    
         
             
                  end
         
     | 
| 
       28 
     | 
    
         
            -
                end
         
     | 
| 
       29 
     | 
    
         
            -
                def chop_last_space
         
     | 
| 
       30 
     | 
    
         
            -
                  @pages.last.sub!(/[[:space:]]+$/, '')
         
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
30 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
                  def created_files
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @pages.created_files
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
                  
         
     | 
| 
      
 35 
     | 
    
         
            +
                  def chop_last_space
         
     | 
| 
      
 36 
     | 
    
         
            +
                    @pages.last.sub!(/[[:space:]]+$/, '')
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
       36 
38 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                     
     | 
| 
      
 39 
     | 
    
         
            +
                  def paragraph_style=(style)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    return if style.nil?
         
     | 
| 
      
 41 
     | 
    
         
            +
                    raise "paragrapy_style accepts only :default or :use_paragraph_group but is #{style}" if style != :default && style != :use_paragraph_group
         
     | 
| 
      
 42 
     | 
    
         
            +
                    @paragraph_style = style
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  
         
     | 
| 
      
 45 
     | 
    
         
            +
                  def paragraph_style
         
     | 
| 
      
 46 
     | 
    
         
            +
                    if @paragraph_style
         
     | 
| 
      
 47 
     | 
    
         
            +
                      @paragraph_style
         
     | 
| 
      
 48 
     | 
    
         
            +
                    elsif @lang.split('-')[0] == 'ja' 
         
     | 
| 
      
 49 
     | 
    
         
            +
                      :use_paragraph_group
         
     | 
| 
      
 50 
     | 
    
         
            +
                    else
         
     | 
| 
      
 51 
     | 
    
         
            +
                      :default
         
     | 
| 
      
 52 
     | 
    
         
            +
                    end
         
     | 
| 
      
 53 
     | 
    
         
            +
                  end
         
     | 
| 
      
 54 
     | 
    
         
            +
                  def head_inserter(&block)
         
     | 
| 
      
 55 
     | 
    
         
            +
                    head_inserters << block
         
     | 
| 
       41 
56 
     | 
    
         
             
                  end
         
     | 
| 
       42 
     | 
    
         
            -
                  page = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
         
     | 
| 
       43 
     | 
    
         
            -
                  page << "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"#{@lang}\" xml:lang=\"#{@lang}\">\n"
         
     | 
| 
       44 
     | 
    
         
            -
                  page << "<head>\n"
         
     | 
| 
       45 
     | 
    
         
            -
                  page << "<title>#{@title}</title>\n"
         
     | 
| 
       46 
     | 
    
         
            -
                  @head_inserters.each {
         
     | 
| 
       47 
     | 
    
         
            -
                    |f|
         
     | 
| 
       48 
     | 
    
         
            -
                    page << f.call
         
     | 
| 
       49 
     | 
    
         
            -
                  }
         
     | 
| 
       50 
     | 
    
         
            -
                  page << "</head>\n"
         
     | 
| 
       51 
     | 
    
         
            -
                  page << "<body>\n"
         
     | 
| 
       52 
     | 
    
         
            -
                  @pages << page
         
     | 
| 
       53 
     | 
    
         
            -
                  @toc << title
         
     | 
| 
       54 
     | 
    
         
            -
                end
         
     | 
| 
       55 
57 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                     
     | 
| 
       61 
     | 
    
         
            -
                    page. 
     | 
| 
      
 58 
     | 
    
         
            +
                  def start_html(title = nil)
         
     | 
| 
      
 59 
     | 
    
         
            +
                    @title = title if !title.nil?
         
     | 
| 
      
 60 
     | 
    
         
            +
                    if @pages.size >0 && !@pages.last.frozen?
         
     | 
| 
      
 61 
     | 
    
         
            +
                      end_html
         
     | 
| 
      
 62 
     | 
    
         
            +
                    end
         
     | 
| 
      
 63 
     | 
    
         
            +
                    page = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
         
     | 
| 
      
 64 
     | 
    
         
            +
                    page << "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"#{@lang}\" xml:lang=\"#{@lang}\">\n"
         
     | 
| 
      
 65 
     | 
    
         
            +
                    page << "<head>\n"
         
     | 
| 
      
 66 
     | 
    
         
            +
                    page << "<title>#{@title}</title>\n"
         
     | 
| 
      
 67 
     | 
    
         
            +
                    @head_inserters.each {
         
     | 
| 
      
 68 
     | 
    
         
            +
                      |f|
         
     | 
| 
      
 69 
     | 
    
         
            +
                      page << f.call
         
     | 
| 
      
 70 
     | 
    
         
            +
                    }
         
     | 
| 
      
 71 
     | 
    
         
            +
                    page << "</head>\n"
         
     | 
| 
      
 72 
     | 
    
         
            +
                    page << "<body>\n"
         
     | 
| 
      
 73 
     | 
    
         
            +
                    @pages << page
         
     | 
| 
      
 74 
     | 
    
         
            +
                    @toc << title
         
     | 
| 
       62 
75 
     | 
    
         
             
                  end
         
     | 
| 
       63 
     | 
    
         
            -
                end
         
     | 
| 
       64 
76 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
      
 77 
     | 
    
         
            +
                  def end_html
         
     | 
| 
      
 78 
     | 
    
         
            +
                    page = @pages.last
         
     | 
| 
      
 79 
     | 
    
         
            +
                    if !page.frozen?
         
     | 
| 
      
 80 
     | 
    
         
            +
                      page << "</body>\n"
         
     | 
| 
      
 81 
     | 
    
         
            +
                      page << "</html>\n"
         
     | 
| 
      
 82 
     | 
    
         
            +
                      page.freeze 
         
     | 
| 
      
 83 
     | 
    
         
            +
                    end
         
     | 
| 
      
 84 
     | 
    
         
            +
                  end
         
     | 
| 
       68 
85 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                   
     | 
| 
       72 
     | 
    
         
            -
                end
         
     | 
| 
      
 86 
     | 
    
         
            +
                  def enter_block(lexed)
         
     | 
| 
      
 87 
     | 
    
         
            +
                    @block_delimiter_stack.push(lexed[:delimiter])
         
     | 
| 
      
 88 
     | 
    
         
            +
                  end
         
     | 
| 
       73 
89 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
      
 90 
     | 
    
         
            +
                  def exit_block(lexed)
         
     | 
| 
      
 91 
     | 
    
         
            +
                    @block_delimiter_stack.pop
         
     | 
| 
      
 92 
     | 
    
         
            +
                    nil
         
     | 
| 
      
 93 
     | 
    
         
            +
                  end
         
     | 
| 
       77 
94 
     | 
    
         | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 95 
     | 
    
         
            +
                  def block_close?(line)
         
     | 
| 
      
 96 
     | 
    
         
            +
                    line == (@block_delimiter_stack.last || '') + '}'
         
     | 
| 
      
 97 
     | 
    
         
            +
                  end
         
     | 
| 
       81 
98 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                    start_html
         
     | 
| 
      
 99 
     | 
    
         
            +
                  def toc=(label)
         
     | 
| 
      
 100 
     | 
    
         
            +
                    @toc[-1] = label if @toc.size > 0
         
     | 
| 
       85 
101 
     | 
    
         
             
                  end
         
     | 
| 
       86 
     | 
    
         
            -
                  @pages.last << text
         
     | 
| 
       87 
     | 
    
         
            -
                end
         
     | 
| 
       88 
102 
     | 
    
         | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
      
 103 
     | 
    
         
            +
                  def <<(text)
         
     | 
| 
      
 104 
     | 
    
         
            +
                    if @pages.size == 0 || @pages.last.frozen?
         
     | 
| 
      
 105 
     | 
    
         
            +
                      start_html
         
     | 
| 
      
 106 
     | 
    
         
            +
                    end
         
     | 
| 
      
 107 
     | 
    
         
            +
                    @pages.last << text
         
     | 
| 
       92 
108 
     | 
    
         
             
                  end
         
     | 
| 
       93 
109 
     | 
    
         | 
| 
       94 
     | 
    
         
            -
                   
     | 
| 
      
 110 
     | 
    
         
            +
                  def result
         
     | 
| 
      
 111 
     | 
    
         
            +
                    if !@pages.last.frozen?
         
     | 
| 
      
 112 
     | 
    
         
            +
                      end_html
         
     | 
| 
      
 113 
     | 
    
         
            +
                    end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                    @pages
         
     | 
| 
      
 116 
     | 
    
         
            +
                  end
         
     | 
| 
       95 
117 
     | 
    
         
             
                end
         
     | 
| 
       96 
118 
     | 
    
         
             
              end
         
     | 
| 
       97 
119 
     | 
    
         
             
            end
         
     | 
| 
       98 
     | 
    
         
            -
            end
         
     |