Skip to content

Commit

Permalink
Merge branch 'fix-fancy-lists-with-roman-numerals'
Browse files Browse the repository at this point in the history
  • Loading branch information
Witiko committed Oct 21, 2023
2 parents 37bcaea + 6c2169e commit 034c66f
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Fixes:
`startNumber`. (59fb97e8)
- Properly parse emphasis at line endings in headings.
(contributed by @lostenderman, #358, #360)
- Fix fancy lists that use roman numerals as markers.
(contributed by @lostenderman, sponsored by ISTQB,
danopolan/istqb_latex#87, #359, #364)

Documentation:

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,16 @@ Acknowledgements
| [<img width="150" src="https://www.fi.muni.cz/images/fi-logo.png">][fimu] | I gratefully acknowledge the funding from the [Faculty of Informatics][fimu] at the [Masaryk University][mu] in Brno, Czech Republic, for the development of the Markdown package in projects [MUNI/33/12/2015][], [MUNI/33/1784/2020][], [MUNI/33/0776/2021][], [MUNI/33/1654/2022][], and [MUNI/33/1658/2022][]. |
| [<img width="150" src="https://cdn.overleaf.com/img/ol-brand/overleaf_og_logo.png">][overleaf] | Extensive user documentation for the Markdown package was kindly written by [Lian Tze Lim][liantze] and published by [Overleaf][]. |
| [<img width="150" src="https://pbs.twimg.com/profile_images/1004769879319334912/6Bh1UthD.jpg">][omedym] | Support for content slicing (Lua options [`shiftHeadings`][option-shift-headings] and [`slice`][option-slice]) and pipe tables (Lua options [`pipeTables`][option-pipe-tables] and [`tableCaptions`][option-table-captions]) was graciously sponsored by [David Vins][dvins] and [Omedym][]. |
| [<img width="150" src="https://www.istqb.org/static/istqb-logo-1b043e800a580724ad223567f9ea57c0.png">][istqb] | The fix for issue [#359][issue-359] was graciously sponsored by the [International Software Testing Qualifications Board (ISTQB)][istqb]. |

[dvins]: https://github.com/dvins "David Vins"
[fimu]: https://www.fi.muni.cz/index.html.en "Faculty of Informatics, Masaryk University"
[ISTQB]: https://www.istqb.org/ "International Software Testing Qualifications Board"
[mu]: https://www.muni.cz/en "Masaryk University"
[Omedym]: https://www.omedym.com/ "Omedym"

[issue-359]: https://github.com/witiko/markdown/issues/359 "First item of a fancy list forms a separate list"

[option-pipe-tables]: https://mirrors.ctan.org/macros/generic/markdown/markdown.html#pipe-tables "Markdown Package User Manual"
[option-shift-headings]: https://mirrors.ctan.org/macros/generic/markdown/markdown.html#option-shiftheadings "Markdown Package User Manual"
[option-slice]: https://mirrors.ctan.org/macros/generic/markdown/markdown.html#slice "Markdown Package User Manual"
Expand Down
57 changes: 36 additions & 21 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -29639,19 +29639,28 @@ M.extensions.fancy_lists = function()
local writer = self.writer

local function combine_markers_and_delims(markers, delims)
local pairs = {}
local markers_table = {}
for _,marker in ipairs(markers) do
local start_marker
local continuation_marker
if type(marker) == "table" then
start_marker = marker[1]
continuation_marker = marker[2]
else
start_marker = marker
continuation_marker = marker
end
for _,delim in ipairs(delims) do
table.insert(pairs, {marker, delim})
table.insert(markers_table, {start_marker, continuation_marker, delim})
end
end
return pairs
return markers_table
end

local function apply_function_to_pairs(func, starter_pairs)
local pattern = func(starter_pairs[1][1], starter_pairs[1][2])
for i = 2, #starter_pairs do
pattern = pattern + func(starter_pairs[i][1], starter_pairs[i][2])
local function join_table_with_func(func, markers_table)
local pattern = func(table.unpack(markers_table[1]))
for i = 2, #markers_table do
pattern = pattern + func(table.unpack(markers_table[i]))
end
return pattern
end
Expand All @@ -29668,12 +29677,17 @@ M.extensions.fancy_lists = function()
* (i*x + i*v + v^-1 * i^-3)
end

local lowercase_roman_marker = roman_marker({"M", "D", "C", "L", "X", "V", "I"})
local uppercase_roman_marker = roman_marker({"m", "d", "c", "l", "x", "v", "i"})
local lowercase_roman_marker = roman_marker({"m", "d", "c", "l", "x", "v", "i"})
local uppercase_roman_marker = roman_marker({"M", "D", "C", "L", "X", "V", "I"})

local lowercase_opening_roman_marker = P("i")
local uppercase_opening_roman_marker = P("I")

local digit_marker = parsers.dig * parsers.dig^-8

local markers = {
{lowercase_opening_roman_marker, lowercase_roman_marker},
{uppercase_opening_roman_marker, uppercase_roman_marker},
lowercase_letter_marker,
uppercase_letter_marker,
lowercase_roman_marker,
Expand All @@ -29686,16 +29700,16 @@ M.extensions.fancy_lists = function()
parsers.rparent
}

local starter_pairs = combine_markers_and_delims(markers, delims)
local markers_table = combine_markers_and_delims(markers, delims)

local enumerator = function(marker_type, delimiter_type, interrupting)
local function enumerator(start_marker, _, delimiter_type, interrupting)
local delimiter_range
local allowed_end
if interrupting then
delimiter_range = P("1")
allowed_end = C(parsers.spacechar^1) * #parsers.linechar
else
delimiter_range = marker_type
delimiter_range = start_marker
allowed_end = C(parsers.spacechar^1) + #(parsers.newline + parsers.eof)
end

Expand All @@ -29704,7 +29718,7 @@ M.extensions.fancy_lists = function()
* allowed_end
end

local starter = apply_function_to_pairs(enumerator, starter_pairs)
local starter = join_table_with_func(enumerator, markers_table)

local TightListItem = function(starter)
return parsers.add_indent(starter, "li")
Expand Down Expand Up @@ -29783,22 +29797,23 @@ M.extensions.fancy_lists = function()
numdelim or "Default")
end

local FancyListOfType = function(marker_type, delimiter_type)
local enumerator = enumerator(marker_type, delimiter_type)
return Cg(enumerator, "listtype")
local FancyListOfType = function(start_marker, continuation_marker, delimiter_type)
local enumerator_start = enumerator(start_marker, continuation_marker, delimiter_type)
local enumerator_cont = enumerator(continuation_marker, continuation_marker, delimiter_type)
return Cg(enumerator_start, "listtype")
* (Ct( TightListItem(Cb("listtype"))
* ((parsers.check_minimal_indent / "") * TightListItem(enumerator))^0)
* ((parsers.check_minimal_indent / "") * TightListItem(enumerator_cont))^0)
* Cc(true)
* -#((parsers.conditionally_indented_blankline^0 / "")
* parsers.check_minimal_indent * enumerator)
* parsers.check_minimal_indent * enumerator_cont)
+ Ct( LooseListItem(Cb("listtype"))
* ((parsers.conditionally_indented_blankline^0 / "")
* (parsers.check_minimal_indent / "") * LooseListItem(enumerator))^0)
* (parsers.check_minimal_indent / "") * LooseListItem(enumerator_cont))^0)
* Cc(false)
) * Ct(Cb("listtype")) / fancylist
end

local FancyList = apply_function_to_pairs(FancyListOfType, starter_pairs)
local FancyList = join_table_with_func(FancyListOfType, markers_table)

local Endline = parsers.newline
* (parsers.check_minimal_indent
Expand Down
83 changes: 82 additions & 1 deletion tests/testfiles/lunamark-markdown/fancy-lists.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This test ensures that the Lua `fancyLists` option correctly propagates
through the plain TeX interface and that the `startNumber` and `tightLists`
options are enabled by default.

Fancy list (*roman, lower, tight*)

i. item
ii. item

Fancy list (*roman, lower*)

iv. item
Expand All @@ -12,7 +17,13 @@ Fancy list (*roman, lower*)

Fancy list (*roman, upper, tight*)

I. item
II. item

Fancy list (*roman, upper*)

IV. item

V. item

Fancy list (*alpha, lower*)
Expand All @@ -36,6 +47,16 @@ Fancy list (*alpha, lower, tight and paren, alpha, lower, tight*)

a. item
b) item

Fancy list (*roman, lower, tight and alpha, lower, tight*)

i. item
j. item

Fancy list (*alpha, lower, tight and roman, lower, tight*)

v. item
vi. item
>>>
BEGIN document
codeSpan: fancyLists
Expand All @@ -44,6 +65,18 @@ codeSpan: startNumber
codeSpan: tightLists
softLineBreak
paragraphSeparator
emphasis: roman, lower, tight
interblockSeparator
BEGIN fancyOlBeginTight
- numstyle: LowerRoman
- numdelim: Period
END fancyOlBeginTight
fancyOlItemWithNumber: 1
fancyOlItemEnd
fancyOlItemWithNumber: 2
fancyOlItemEnd
fancyOlEndTight
interblockSeparator
emphasis: roman, lower
interblockSeparator
BEGIN fancyOlBegin
Expand All @@ -62,11 +95,23 @@ BEGIN fancyOlBeginTight
- numstyle: UpperRoman
- numdelim: Period
END fancyOlBeginTight
fancyOlItemWithNumber: 1
fancyOlItemEnd
fancyOlItemWithNumber: 2
fancyOlItemEnd
fancyOlEndTight
interblockSeparator
emphasis: roman, upper
interblockSeparator
BEGIN fancyOlBegin
- numstyle: UpperRoman
- numdelim: Period
END fancyOlBegin
fancyOlItemWithNumber: 4
fancyOlItemEnd
fancyOlItemWithNumber: 5
fancyOlItemEnd
fancyOlEndTight
fancyOlEnd
interblockSeparator
emphasis: alpha, lower
interblockSeparator
Expand Down Expand Up @@ -121,4 +166,40 @@ END fancyOlBeginTight
fancyOlItemWithNumber: 2
fancyOlItemEnd
fancyOlEndTight
interblockSeparator
emphasis: roman, lower, tight and alpha, lower, tight
interblockSeparator
BEGIN fancyOlBeginTight
- numstyle: LowerRoman
- numdelim: Period
END fancyOlBeginTight
fancyOlItemWithNumber: 1
fancyOlItemEnd
fancyOlEndTight
interblockSeparator
BEGIN fancyOlBeginTight
- numstyle: LowerAlpha
- numdelim: Period
END fancyOlBeginTight
fancyOlItemWithNumber: 10
fancyOlItemEnd
fancyOlEndTight
interblockSeparator
emphasis: alpha, lower, tight and roman, lower, tight
interblockSeparator
BEGIN fancyOlBeginTight
- numstyle: LowerAlpha
- numdelim: Period
END fancyOlBeginTight
fancyOlItemWithNumber: 22
fancyOlItemEnd
fancyOlEndTight
interblockSeparator
BEGIN fancyOlBeginTight
- numstyle: LowerRoman
- numdelim: Period
END fancyOlBeginTight
fancyOlItemWithNumber: 6
fancyOlItemEnd
fancyOlEndTight
END document

0 comments on commit 034c66f

Please sign in to comment.