[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge branch 'feat/remove-dependency-on-unicode-data.txt'
Browse files Browse the repository at this point in the history
  • Loading branch information
Witiko committed Sep 16, 2024
2 parents c4ef2e4 + d21e526 commit 5a8f4a3
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## 3.7.1

Development:

- Remove dependency on `UnicodeData.txt`. (#400, #458 #486, #492, #499)

This change adds a new file `markdown-unicode-data.lua`, which must
be properly installed with the rest of the Markdown package for TeX.

Fixes:

- Properly load LaTeX themes when `theme` or `import` is used in
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ make -C ${BUILD_DIR} base
mkdir -p ${INSTALL_DIR}/tex/luatex/markdown/
cp ${BUILD_DIR}/markdown.lua ${INSTALL_DIR}/tex/luatex/markdown/
cp ${BUILD_DIR}/markdown-parser.lua ${INSTALL_DIR}/tex/luatex/markdown/
cp ${BUILD_DIR}/markdown-unicode-data.lua ${INSTALL_DIR}/tex/luatex/markdown/
cp ${BUILD_DIR}/libraries/markdown-tinyyaml.lua ${INSTALL_DIR}/tex/luatex/markdown/
mkdir -p ${INSTALL_DIR}/scripts/markdown/
cp ${BUILD_DIR}/markdown-cli.lua ${INSTALL_DIR}/scripts/markdown/
Expand Down
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AUXFILES=markdown.bbl markdown.cb markdown.cb2 markdown.glo markdown.bbl \
markdown.run.xml markdown.markdown.in markdown.markdown.lua \
markdown.markdown.out markdown-interfaces.md markdown-miscellanea.md \
markdown-options.md markdown-tokens.md $(TECHNICAL_DOCUMENTATION_RESOURCES) \
$(VERSION_FILE) $(RAW_DEPENDENCIES)
$(VERSION_FILE) $(RAW_DEPENDENCIES) markdown-unicode-data-generator.lua
AUXDIRS=_minted-markdown _markdown_markdown markdown pkgcheck
TDSARCHIVE=markdown.tds.zip
CTANARCHIVE=markdown.ctan.zip
Expand Down Expand Up @@ -45,10 +45,11 @@ USER_MANUAL=$(MARKDOWN_USER_MANUAL) $(HTML_USER_MANUAL)
DOCUMENTATION=$(TECHNICAL_DOCUMENTATION) $(HTML_USER_MANUAL) $(ROOT_README) $(VERSION_FILE) \
$(CHANGES_FILE) $(DEPENDENCIES)
LIBRARIES=libraries/markdown-tinyyaml.lua
INSTALLABLES=markdown.lua markdown-parser.lua markdown-cli.lua markdown.tex markdown.sty \
t-markdown.tex markdownthemewitiko_dot.sty markdownthemewitiko_graphicx_http.sty \
markdownthemewitiko_tilde.tex markdownthemewitiko_markdown_defaults.tex \
markdownthemewitiko_markdown_defaults.sty t-markdownthemewitiko_markdown_defaults.tex
INSTALLABLES=markdown.lua markdown-parser.lua markdown-cli.lua markdown-unicode-data.lua \
markdown.tex markdown.sty t-markdown.tex markdownthemewitiko_dot.sty \
markdownthemewitiko_graphicx_http.sty markdownthemewitiko_tilde.tex \
markdownthemewitiko_markdown_defaults.tex markdownthemewitiko_markdown_defaults.sty \
t-markdownthemewitiko_markdown_defaults.tex
EXTRACTABLES=$(INSTALLABLES) $(MARKDOWN_USER_MANUAL) $(TECHNICAL_DOCUMENTATION_RESOURCES) \
$(RAW_DEPENDENCIES)
MAKEABLES=$(TECHNICAL_DOCUMENTATION) $(USER_MANUAL) $(INSTALLABLES) $(EXAMPLES) $(DEPENDENCIES)
Expand Down Expand Up @@ -129,6 +130,7 @@ $(GITHUB_PAGES): $(HTML_USER_MANUAL)
# This target extracts the source files out of the DTX archive.
$(EXTRACTABLES): $(INSTALLER) $(DTXARCHIVE)
luatex $<
texlua markdown-unicode-data-generator.lua >> markdown-unicode-data.lua
sed -i \
-e 's#(((VERSION)))#$(VERSION)#g' \
-e 's#(((SHORTVERSION)))#$(SHORTVERSION)#g' \
Expand Down Expand Up @@ -225,7 +227,8 @@ $(TDSARCHIVE): $(DTXARCHIVE) $(INSTALLER) $(INSTALLABLES) $(DOCUMENTATION) $(EXA
@# Installing the macro package.
mkdir -p tex/generic/markdown tex/luatex/markdown tex/latex/markdown \
tex/context/third/markdown scripts/markdown
cp markdown.lua markdown-parser.lua $(LIBRARIES) tex/luatex/markdown/
cp markdown.lua markdown-parser.lua markdown-unicode-data.lua $(LIBRARIES) \
tex/luatex/markdown/
cp markdown-cli.lua scripts/markdown/
cp markdown.tex markdownthemewitiko_tilde.tex \
markdownthemewitiko_markdown_defaults.tex tex/generic/markdown/
Expand Down Expand Up @@ -274,7 +277,7 @@ implode: clean

# This pseudo-target checks that the length of lines in the source files.
check-line-length: $(INSTALLABLES)
! grep -n -E '^.{73,}$$' $^
! grep -n -E '^.{73,}$$' $(filter-out markdown-unicode-data.lua,$^)

# This pseudo-target checks for tabs and trailing spaces in the source files.
check-tabs-and-spaces: $(DTXARCHIVE)
Expand Down
104 changes: 84 additions & 20 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ documentation][techdoc].
(A Markdown Interpreter for TeX)

%</manual>
%<*lua,lua-cli,lua-loader>
%<*lua,lua-cli,lua-loader,lua-unicode-data>
% \fi
% \begin{macrocode}
local metadata = {
Expand All @@ -941,7 +941,7 @@ local metadata = {

% \end{macrocode}
% \iffalse
%</lua,lua-cli,lua-loader>
%</lua,lua-cli,lua-loader,lua-unicode-data>
%<*lua>
% \fi
% \begin{macrocode}
Expand Down Expand Up @@ -993,7 +993,7 @@ make base

Either of the two abovelisted approaches should produce the following files:

* `markdown.lua` and `markdown-parser.lua`: The Lua module
* `markdown.lua`, `markdown-parser.lua`, and `markdown-unicode-data.lua`: The Lua module
* `libraries/markdown-tinyyaml.lua`: An external library for reading \acro{yaml}
* `markdown-cli.lua`: The Lua command-line interface
* `markdown.tex`: The plain \TeX{} macro package
Expand All @@ -1015,6 +1015,7 @@ placed:

* `⟨TEXMF⟩/tex/luatex/markdown/markdown.lua`
* `⟨TEXMF⟩/tex/luatex/markdown/markdown-parser.lua`
* `⟨TEXMF⟩/tex/luatex/markdown/markdown-unicode-data.lua`
* `⟨TEXMF⟩/tex/luatex/markdown/markdown-tinyyaml.lua`
* `⟨TEXMF⟩/scripts/markdown/markdown-cli.lua`
* `⟨TEXMF⟩/tex/generic/markdown/markdown.tex`
Expand Down Expand Up @@ -1042,6 +1043,7 @@ This is where the individual files should be placed:

* `./markdown.lua`
* `./markdown-parser.lua`
* `./markdown-unicode-data.lua`
* `./markdown-tinyyaml.lua`
* `./markdown-cli.lua`
* `./markdown/markdown.tex`
Expand Down Expand Up @@ -1082,6 +1084,10 @@ The file `markdown.tex` *must* be placed in a directory named `markdown`.
% Live${}\geq{}2013$).
%
% \end{markdown}
% \iffalse
%</lua>
%<*lua,lua-unicode-data>
% \fi
% \begin{macrocode}
local lpeg = require("lpeg")
% \end{macrocode}
Expand All @@ -1096,6 +1102,10 @@ local lpeg = require("lpeg")
% Lua\TeX{} (\TeX Live${}\geq{}2008$).
%
% \end{markdown}
% \iffalse
%</lua,lua-unicode-data>
%<*lua,lua-unicode-data-generator>
% \fi
% \begin{macrocode}
local unicode = require("unicode")
% \end{macrocode}
Expand All @@ -1111,15 +1121,15 @@ local unicode = require("unicode")
%
% \end{markdown}
% \iffalse
%</lua>
%</lua,lua-unicode-data-generator>
%<*lua,lua-loader>
% \fi
% \begin{macrocode}
local md5 = require("md5");
local md5 = require("md5")
% \end{macrocode}
% \iffalse
%</lua,lua-loader>
%<*lua>
%<*lua,lua-unicode-data-generator>
% \fi
% \begin{markdown}
%
Expand All @@ -1130,7 +1140,7 @@ local md5 = require("md5");
%
% \end{markdown}
% \begin{macrocode}
(function()
;(function()
% \end{macrocode}
% \begin{markdown}
%
Expand Down Expand Up @@ -1164,7 +1174,7 @@ end)()
%
% \end{markdown}
% \iffalse
%</lua>
%</lua,lua-unicode-data-generator>
%<*depends>
% \fi
% \begin{macrocode}
Expand Down Expand Up @@ -1885,7 +1895,7 @@ module and a command-line interface (CLI).
(Lua library for conversion between markup formats)

%</manual-interfaces>
%<*lua,lua-loader>
%<*lua,lua-loader,lua-unicode-data>
% \fi
% \begin{markdown}
%
Expand All @@ -1902,7 +1912,7 @@ local M = {metadata = metadata}
% \end{macrocode}
% \iffalse
% \fi
%</lua,lua-loader>
%</lua,lua-loader,lua-unicode-data>
%<*lua>
% \par
% \begin{markdown}
Expand Down Expand Up @@ -26666,8 +26676,13 @@ parsers.fail = P(false)

parsers.internal_punctuation = S(":;,.?")
parsers.ascii_punctuation = S("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")

% \end{macrocode}
% \par
% \iffalse
%</lua>
%<*lua-unicode-data-generator>
% \fi
% \begin{markdown}
%
%### Unicode punctuation
Expand All @@ -26679,6 +26694,11 @@ parsers.ascii_punctuation = S("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
% [unicode-punctuation]: https://spec.commonmark.org/0.31.2/#unicode-punctuation-character
% (CommonMark Spec, Version 0.31.2 (2024-01-28))
%
% All code from this section will be executed during the compilation of
% the Markdown package and the standard output will be stored in a file
% named `markdown-unicode-data.lua` with the precompiled parser parser
% of Unicode punctuation.
%
% \end{markdown}
% \begin{macrocode}
;(function()
Expand Down Expand Up @@ -26719,6 +26739,7 @@ parsers.ascii_punctuation = S("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
end
end
assert(file:close())

% \end{macrocode}
% \par
% \begin{markdown}
Expand All @@ -26739,29 +26760,72 @@ parsers.ascii_punctuation = S("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
leave(node, path)
end

parsers.punctuation = {}
print("M.punctuation = {}")
print("local S = lpeg.S")
print("-- luacheck: push no max line length")
for length, prefix_tree in pairs(prefix_trees) do
local subparsers = {}
depth_first_search(prefix_tree, "", function(node, path)
if type(node) == "table" then
subparsers[path] = parsers.fail
else
assert(type(node) == "string")
subparsers[path] = subparsers[path] + S(node)
if type(node) == "string" then
local suffix
if node == "]" then
suffix = "S('" .. node .. "')"
else
suffix = "S([[" .. node .. "]])"
end
if subparsers[path] ~= nil then
subparsers[path] = subparsers[path] .. " + " .. suffix
else
subparsers[path] = suffix
end
end
end, function(_, path)
if #path > 0 then
local byte = path:sub(#path, #path)
local parent_path = path:sub(1, #path-1)
subparsers[parent_path] = subparsers[parent_path]
+ S(byte) * subparsers[path]
if subparsers[path] ~= nil then
local suffix
if byte == "]" then
suffix = "S('" .. byte .. "')"
else
suffix = "S([[" .. byte .. "]])"
end
suffix = suffix .. " * (" .. subparsers[path] .. ")"
if subparsers[parent_path] ~= nil then
subparsers[parent_path] = subparsers[parent_path]
.. " + " .. suffix
else
subparsers[parent_path] = suffix
end
end
else
parsers.punctuation[length] = subparsers[path]
print("M.punctuation[" .. length .. "] = " .. subparsers[path])
end
end)
assert(parsers.punctuation[length] ~= nil)
end
print("-- luacheck: pop")
end)()
print("return M")
% \end{macrocode}
% \par
% \iffalse
%</lua-unicode-data-generator>
%<*lua>
% \fi
% \begin{markdown}
%
% Back in the Markdown package, we will load the precompiled parser of
% Unicode punctuation.
%
% \end{markdown}
% \begin{macrocode}
local unicode_data = require("markdown-unicode-data")
if metadata.version ~= unicode_data.metadata.version then
warn("markdown.lua " .. metadata.version .. " used with " ..
"markdown-unicode-data.lua " .. unicode_data.metadata.version ..
".")
end
parsers.punctuation = unicode_data.punctuation

parsers.escapable = parsers.ascii_punctuation
parsers.anyescaped = parsers.backslash / ""
Expand Down
2 changes: 2 additions & 0 deletions markdown.ins
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
\file{markdown.lua}{\from{markdown.dtx}{lua-loader}}
\file{markdown-parser.lua}{\from{markdown.dtx}{lua}}
\file{markdown-cli.lua}{\from{markdown.dtx}{lua-cli}}
\file{markdown-unicode-data-generator.lua}{\from{markdown.dtx}{lua-unicode-data-generator}}
\file{markdown-unicode-data.lua}{\from{markdown.dtx}{lua-unicode-data}}
\usepreamble\texpreamble
\usepostamble\texpostamble
\file{markdown.tex}{\from{markdown.dtx}{tex}}
Expand Down

0 comments on commit 5a8f4a3

Please sign in to comment.