summaryrefslogtreecommitdiff
path: root/rst_context.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rst_context.lua')
-rw-r--r--rst_context.lua43
1 files changed, 40 insertions, 3 deletions
diff --git a/rst_context.lua b/rst_context.lua
index f41fd6a..9e69374 100644
--- a/rst_context.lua
+++ b/rst_context.lua
@@ -19,6 +19,8 @@ require "lpeg"
help = require "rst_helpers"
rst_directives = require "rst_directives"
+local utf = unicode.utf8
+
local dbg_write = help.dbg_writef
local C, Cb, Cc, Cg, Cmt, Cp, Cs, Ct, P, R, S, V, match = lpeg.C, lpeg.Cb, lpeg.Cc, lpeg.Cg, lpeg.Cmt, lpeg.Cp, lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.match
@@ -132,6 +134,36 @@ function rst_context.literal (str)
--return [[\\starttyping ]] .. str .. [[\\stoptyping]]
end
+rst_context.roles = {}
+rst_context.roles.emphasis = rst_context.emphasis
+rst_context.roles.strong_emphasis = rst_context.strong_emphasis
+rst_context.roles.literal = rst_context.literal
+rst_context.roles.bold = function(str)
+ return [[{\\bf ]] .. str .. [[}]]
+end
+
+rst_context.roles.ss = function(str)
+ return [[{\\ss ]] .. str .. [[}]]
+end
+rst_context.roles.sans_serif = rst_context.roles.ss
+
+rst_context.roles.uppercase = function(str)
+ return utf.upper(str)
+end
+
+rst_context.roles.lowercase = function(str)
+ return utf.lower(str)
+end
+
+rst_context.roles.color = function(color, str)
+ local p = helpers.patterns
+ local definition = color:match("^color_(.+)$")
+ if definition:match("^rgb_") then -- assume rgb
+ local rgb = p.rgbvalues:match(definition)
+ definition = string.format([[r=%s,g=%s,b=%s]], rgb[1], rgb[2], rgb[3])
+ end
+ return string.format([[\\colored[%s]{%s}]], definition, str)
+end
function rst_context.interpreted_text (...)
local tab = { ... }
@@ -143,7 +175,11 @@ function rst_context.interpreted_text (...)
role = "emphasis"
end
- return rst_context[role](str)
+ if role:match("^color_") then
+ return rst_context.roles.color(role, str)
+ end
+
+ return rst_context.roles[role](str)
end
function rst_context.link_standalone (str)
@@ -264,9 +300,9 @@ local inline_parser = P{
inline_do_elements = V"strong_emphasis"
+ V"substitution_reference"
+ V"anon_reference"
+ + V"inline_literal"
+ V"reference"
+ V"emphasis"
- + V"inline_literal"
+ V"interpreted_text"
+ V"inline_internal_target"
+ V"link_standalone"
@@ -320,6 +356,7 @@ local inline_parser = P{
double_bareia = V"bareia" * V"bareia",
escaped_bareia = (Cs(V"backslash") / "" * V"bareia") + 1,
colon = P":",
+ escaped_colon = (Cs(V"backslash") / "" * V"colon") + 1,
semicolon = P";",
underscore = P"_",
double_underscore = V"underscore" * V"underscore",
@@ -410,7 +447,7 @@ local inline_parser = P{
* C(V"role_marker"^-1)
/ rst_context.interpreted_text,
- role_marker = V"colon" * (V"letter" + V"dash" + V"underscore" + V"dot")^1 * V"colon",
+ role_marker = V"colon" * (V"backslash" * V"colon" + V"letter" + V"digit" + V"dash" + V"underscore" + V"dot")^1 * V"colon",
link_standalone = C(V"uri")
/ rst_context.link_standalone,