From cb987930f25cd75d336f192affc1a84c019fb233 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 25 Mar 2025 17:34:17 -0400 Subject: [PATCH] Force lists to be "loose" style (wrap text in

tags) --- shared/naturalcrit/markdown.js | 14 ++++++++++++++ themes/V3/5ePHB/style.less | 8 ++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index bed109772..3b034e44b 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -381,7 +381,12 @@ const forcedParagraphBreaks = { tokenizer(src, tokens) { const regex = /^(:+)(?:\n|$)/ym; const match = regex.exec(src); + if(match?.length) { + const lastToken = tokens[tokens.length - 1]; + if(lastToken?.type == 'text') + lastToken.type = 'paragraph'; + return { type : 'hardBreaks', // Should match "name" above raw : match[0], // Text to consume from the source @@ -395,6 +400,14 @@ const forcedParagraphBreaks = { } }; +const patchHardBreaks = { + walkTokens(token) { + if(token.type == 'list' || token.type == 'list_item') { + token.loose = true; + } + } +} + const nonbreakingSpaces = { name : 'nonbreakingSpaces', level : 'inline', @@ -774,6 +787,7 @@ Marked.use(MarkedVariables()); Marked.use({ extensions : [justifiedParagraphs, definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks, nonbreakingSpaces, mustacheSpans, mustacheDivs, mustacheInjectInline] }); Marked.use(mustacheInjectBlock); +Marked.use(patchHardBreaks); Marked.use(MarkedSubSuperText()); Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false }); Marked.use(MarkedExtendedTables({interruptPatterns : tableTerminators}), MarkedGFMHeadingId({ globalSlugs: true }), diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 5eebcb12e..f910f6173 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -57,12 +57,13 @@ ul { padding-left : 1.4em; margin-bottom : 0.8em; - line-height : 1.25em; } ol { padding-left : 1.4em; margin-bottom : 0.8em; - line-height : 1.25em; + } + .page li p { + line-height : 1.25em; } //Indents after p or lists p + p, ul + p, ol + p { text-indent : 1em; } @@ -137,6 +138,9 @@ line-height : 0.951em; //Font is misaligned. Shift up slightly & + * { margin-top : 0.2cm; } } + br + h3, br + h4 { + margin-top : 0; + } // ***************************** // * TABLE // *****************************/