Commits

Philipp Gesang committed b146324

pass through (escape) {brackets,braces} from input

  • Participants
  • Parent commits bf471e0

Comments (0)

Files changed (2)

File mod/tex/context/third/rst/rst_context.lua

     }
     function string.strip(str)
         return stripper:match(str) or ""
-    end 
+    end
 end
 local stringstrip = string.strip
 local fmt         = string.format
         skip2    = P"\\type" * V"balanced",
         skip3    = P"\\mathematics" * V"balanced",
         skip     = V"skip1" + V"skip2" + V"skip3",
-        --literal  = Cs(P"\\" / "") * 1 
+        --literal  = Cs(P"\\" / "") * 1
     }
 
     function rst_context.escape (str)
 local inline_parser = P{
     [1] = "block",
 
-    block = Cs(V"inline_as_first"^-1 * (V"except" + V"inline_element" + 1)^0),
+    block = Cs(V"inline_as_first"^-1 * (V"except" + V"inline_element" + V"normal_char")^0),
 
     inline_element = V"precede_inline"
-                    * Cs(V"inline_do_elements")
-                    * #V"succede_inline"
-                    + V"footnote_reference"
-                    ,
+                   * Cs(V"inline_do_elements")
+                   * #V"succede_inline"
+                   + V"footnote_reference"
+                   ,
 
     -- Ugly but needed in case the first element of a paragraph is inline
     -- formatted.
            ,
 
     inline_do_elements = V"strong_emphasis"
-                     + V"substitution_reference"
-                     + V"anon_reference"
-                     + V"inline_literal"
-                     + V"reference"
-                     + V"emphasis"
-                     + V"interpreted_text"
-                     + V"inline_internal_target"
-                     + V"link_standalone"
-                     ,
+                       + V"substitution_reference"
+                       + V"anon_reference"
+                       + V"inline_literal"
+                       + V"reference"
+                       + V"emphasis"
+                       + V"interpreted_text"
+                       + V"inline_internal_target"
+                       + V"link_standalone"
+                       ,
 
     precede_inline = V"spacing"
                    + V"eol"
 
     lparenthesis = P"(",
     rparenthesis = P")",
-    lsquare = P"[",
-    rsquare = P"]",
-    lbrace = P"{",
-    rbrace = P"}",
+    lsquare = P"[" / [[{\\letterleftbracket}]],
+    rsquare = P"]" / [[{\\letterrightbracket}]],
+    lbrace  = P"{" / [[{\\letterleftbrace}]],
+    rbrace  = P"}" / [[{\\letterrightbrace}]],
     less    = P"<",
     greater = P">",
     leftpar  = V"lparenthesis" + V"lsquare" + V"lbrace" + V"less",
     rightpar = V"rparenthesis" + V"rsquare" + V"rbrace" + V"greater",
 
+    normal_char = V"lbrace" + V"rbrace" + V"lsquare" + V"rsquare" -- escape those if in input
+                + 1
+                ,
+
     --groupchars = S"()[]{}",
     groupchars = V"leftpar" + V"rightpar",
     apostrophe = P"’" + P"'",
     letter = R"az" + R"AZ",
 
     punctuation = V"apostrophe"
-                + V"colon" 
-                + V"comma" 
+                + V"colon"
+                + V"comma"
                 + V"dashes"
-                + V"dot" 
+                + V"dot"
                 + V"ellipsis"
                 + V"exclamationmark"
                 + V"guillemets"
                 + V"hyphen"
                 + V"interpunct"
                 + V"interrobang"
-                + V"questionmark" 
+                + V"questionmark"
                 + V"quotationmarks"
-                + V"semicolon" 
+                + V"semicolon"
                 + V"slash"
                 + V"solidus"
                 + V"underscore"
                 ,
 
-    emphasis        = (V"asterisk" - V"double_asterisk") 
+    emphasis        = (V"asterisk" - V"double_asterisk")
                     * Cs((1 - V"spacing" - V"eol" - V"asterisk")
-                       * ((1 - (1 * V"asterisk"))^0 
-                        * (1 - V"spacing" - V"eol" - V"asterisk"))^-1) 
-                    * V"asterisk" 
+                       * ((1 - (1 * V"asterisk"))^0
+                        * (1 - V"spacing" - V"eol" - V"asterisk"))^-1)
+                    * V"asterisk"
                     / rst_context.emphasis,
 
-    strong_emphasis = V"double_asterisk" 
+    strong_emphasis = V"double_asterisk"
                     * Cs((1 - V"spacing" - V"eol" - V"asterisk")
-                       * ((1 - (1 * V"double_asterisk"))^0 
-                        * (1 - V"spacing" - V"eol" - V"asterisk"))^-1) 
-                    * V"double_asterisk"  
+                       * ((1 - (1 * V"double_asterisk"))^0
+                        * (1 - V"spacing" - V"eol" - V"asterisk"))^-1)
+                    * V"double_asterisk"
                     / rst_context.strong_emphasis,
 
     inline_literal  = V"double_bareia"
                      * V"bareia" * V"underscore"
                      ,
 
-    footnote_reference = V"lsquare" 
-                       * Cs(V"footnote_label" + V"citation_reference_label") 
-                       * V"rsquare" 
+    footnote_reference = V"lsquare"
+                       * Cs(V"footnote_label" + V"citation_reference_label")
+                       * V"rsquare"
                        * V"underscore"
                        / rst_context.footnote_reference
                        ,

File mod/tex/context/third/rst/rst_parser.lua

                       * C((1 - V"bar" - V"eol")^1)
                       * V"bar"
                       ,
-                     
+
     data_directive_block = V"data_directive_block_long"
                          + V"data_directive_block_short"
                          ,
                     end)
                   * (1 - V"eol")^1 * V"eol"
                   ,
-    
+
     fn_matchindent = Cmt(V"space"^1, function(s, i, indent)
                         local tc = state.currentindent
                         warn("fn-ma", tc == indent, #tc, #indent, i)
 
     st_first_row = V"st_setindent"
                  * C(V"st_setlayout")
-                 * V"space"^0 
+                 * V"space"^0
                  * V"eol"
                  ,
 
 
 
     punctuation = V"apostrophe"
-                + V"colon" 
-                + V"comma" 
+                + V"colon"
+                + V"comma"
                 + V"dashes"
-                + V"dot" 
+                + V"dot"
                 + V"ellipsis"
                 + V"exclamationmark"
                 + V"guillemets"
                 + V"hyphen"
                 + V"interpunct"
                 + V"interrobang"
-                + V"questionmark" 
+                + V"questionmark"
                 + V"quotationmarks"
-                + V"semicolon" 
+                + V"semicolon"
                 + V"slash"
                 + V"solidus"
                 + V"underscore"
 
     letter       = R"az" + R"AZ",
     digit        = R"09",
-                 
+
     space        = P" ",
     spaces       = V"space"^1,
     whitespace   = (P" " + Cs(P"\t") / "        " + Cs(S"\v") / " "),
         tmp = fh.crlf(tmp)
     end
     if thirddata.rst.expandtab then
-        tmp = fh.expandtab(tmp) 
+        tmp = fh.expandtab(tmp)
     end
     return fh.insert_blank(tmp)
 end