From bc3bb79d16c52531387c70c24f94513b62dcfa67 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 20 Aug 2011 21:55:36 +0200 Subject: optional BOM trimming --- doc/manual.bib | 10 ---------- mod/doc/context/third/rst/manual.bib | 10 ++++++++++ mod/tex/context/third/rst/rst_parser.lua | 11 +++++++++++ mod/tex/context/third/rst/t-rst.mkiv | 12 +++++++++++- 4 files changed, 32 insertions(+), 11 deletions(-) delete mode 100644 doc/manual.bib create mode 100644 mod/doc/context/third/rst/manual.bib diff --git a/doc/manual.bib b/doc/manual.bib deleted file mode 100644 index 638ed80..0000000 --- a/doc/manual.bib +++ /dev/null @@ -1,10 +0,0 @@ -@BOOK{texbook, - author = {Donald E. Knuth}, - title = {The \TEX book}, - year = {1984}, - address = {Reading, Mass. et. al.}, - location = {Reading, Mass. et. al.}, - series = {Computers and typesetting vol. 1}, - keywords = {all} -} - diff --git a/mod/doc/context/third/rst/manual.bib b/mod/doc/context/third/rst/manual.bib new file mode 100644 index 0000000..638ed80 --- /dev/null +++ b/mod/doc/context/third/rst/manual.bib @@ -0,0 +1,10 @@ +@BOOK{texbook, + author = {Donald E. Knuth}, + title = {The \TEX book}, + year = {1984}, + address = {Reading, Mass. et. al.}, + location = {Reading, Mass. et. al.}, + series = {Computers and typesetting vol. 1}, + keywords = {all} +} + diff --git a/mod/tex/context/third/rst/rst_parser.lua b/mod/tex/context/third/rst/rst_parser.lua index 6aeeb7d..f5c9fbc 100644 --- a/mod/tex/context/third/rst/rst_parser.lua +++ b/mod/tex/context/third/rst/rst_parser.lua @@ -34,6 +34,7 @@ else rst = require "rst_context" end +rst.stripBOM = false helpers.rst_debug = false local warn = function(str, ...) @@ -1350,11 +1351,21 @@ local parser = P{ table_header_hline = P"=", } +local function strip_BOM (raw) + if raw:match"^\239\187\191" then + return raw:sub(4) + end + return raw +end + local function load_file (name) f = assert(io.open(name, "r"), "Not a file!") if not f then return 1 end local tmp = f:read("*all") f:close() + if rst.strip_BOM then + return strip_BOM(tmp) + end return tmp end diff --git a/mod/tex/context/third/rst/t-rst.mkiv b/mod/tex/context/third/rst/t-rst.mkiv index 0359335..0a3e25b 100644 --- a/mod/tex/context/third/rst/t-rst.mkiv +++ b/mod/tex/context/third/rst/t-rst.mkiv @@ -114,7 +114,17 @@ %D %D \showsetup{typesetRSTfile} -\def\typesetRSTfile#1{\ctxlua{thirddata.rst.do_rst_file("#1")}} +\def\do_typesetRSTfile[#1]#2{% + \iffirstargument + \getparameters[RST][#1]% + \doifdefined{\RSTstripBOM}{\ctxlua{thirddata.rst.strip_BOM = "\RSTstripBOM"}}% + \fi + \ctxlua{thirddata.rst.do_rst_file("#2")}% +} + +\def\typesetRSTfile{% + \dosingleempty\do_typesetRSTfile% +} %D \subsection{Typesetting Inline Snippets} %D -- cgit v1.2.3