Skip to content

Commit 23b157a

Browse files
committed
Make block-level markdown a Markup Shorthands option
This will be enabled by HTML for a slight speed improvement, and not having to carefully escape/indent certain things in the initial conversion. We might later want to turn it on again.
1 parent caf5136 commit 23b157a

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

bikeshed/Spec.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,16 @@ def assembleDocument(self) -> Spec:
228228
# Deal with further <pre> blocks, and markdown
229229
self.lines = datablocks.transformDataBlocks(self, self.lines)
230230

231-
markdownFeatures: set[str] = {"headings"}
232-
self.lines = markdown.parse(
233-
self.lines,
234-
self.md.indent,
235-
opaqueElements=self.md.opaqueElements,
236-
blockElements=self.md.blockElements,
237-
features=markdownFeatures,
238-
)
231+
parseConfig = h.ParseConfig.fromSpec(self)
232+
if parseConfig.markdownBlock:
233+
markdownFeatures: set[str] = {"headings"}
234+
self.lines = markdown.parse(
235+
self.lines,
236+
self.md.indent,
237+
opaqueElements=self.md.opaqueElements,
238+
blockElements=self.md.blockElements,
239+
features=markdownFeatures,
240+
)
239241

240242
self.refs.setSpecData(self)
241243

bikeshed/h/parser/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def parseNode(
225225
el, i, _ = parseFencedCodeBlock(s, start)
226226
if el is not None:
227227
return Ok(el, i)
228-
if s.config.markdown:
228+
if s.config.markdownInline:
229229
if first2 == r"\`":
230230
node = RawText.fromStream(s, start, start + 2, "`")
231231
return Ok(node, start + 2)
@@ -378,7 +378,7 @@ def parseNode(
378378
biblioRes = parseAutolinkBiblioSection(s, start)
379379
if isOk(biblioRes):
380380
return biblioRes
381-
if s.config.markdown and not inOpaque:
381+
if s.config.markdownInline and not inOpaque:
382382
if first2 == "\\[":
383383
node = RawText.fromStream(s, start, start + 2, "[")
384384
return Ok(node, start + 2)

bikeshed/h/parser/stream.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class ParseConfig:
2323
header: bool = False
2424
idl: bool = False
2525
macrosInAutolinks: bool = False
26-
markdown: bool = False
26+
markdownBlock: bool = False
27+
markdownInline: bool = False
2728
markdownEscapes: bool = False
2829
markup: bool = False
2930
repositoryLinks: bool = False
@@ -42,7 +43,8 @@ def fromSpec(doc: t.SpecT, context: str | None = None) -> ParseConfig:
4243
header="http" in doc.md.markupShorthands,
4344
idl="idl" in doc.md.markupShorthands,
4445
macrosInAutolinks="macros-in-autolinks" in doc.md.markupShorthands,
45-
markdown="markdown" in doc.md.markupShorthands,
46+
markdownBlock="markdown-block" in doc.md.markupShorthands,
47+
markdownInline="markdown-inline" in doc.md.markupShorthands,
4648
markdownEscapes="markdown-escapes" in doc.md.markupShorthands,
4749
markup="markup" in doc.md.markupShorthands,
4850
repositoryLinks="repository-links" in doc.md.markupShorthands,

bikeshed/metadata.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,18 @@ def __init__(self) -> None:
109109
self.mailingList: str | None = None
110110
self.mailingListArchives: str | None = None
111111
self.markupShorthands: config.BoolSet = config.BoolSet(
112-
["css", "dfn", "biblio", "markup", "http", "idl", "cddl", "algorithm", "repository-links"],
112+
[
113+
"css",
114+
"dfn",
115+
"biblio",
116+
"markdown-block",
117+
"markup",
118+
"http",
119+
"idl",
120+
"cddl",
121+
"algorithm",
122+
"repository-links",
123+
],
113124
)
114125
self.maxToCDepth: int | float | None = float("inf")
115126
self.metadataInclude: config.BoolSet = config.BoolSet(default=True)
@@ -760,7 +771,7 @@ def parseLinkedText(key: str, val: str, lineNum: str | int | None) -> list[tuple
760771
def parseMarkupShorthands(key: str, val: str, lineNum: str | int | None) -> config.BoolSet:
761772
# Format is comma-separated list of shorthand category followed by boolean.
762773
# Output is a boolset of the shorthand categories.
763-
# TODO: Just call parseBoolistList instead
774+
# TODO: Just call parseBoolishList instead
764775
vals = [v.strip() for v in val.lower().split(",")]
765776
ret = config.BoolSet(default=False)
766777
validCategories = frozenset(
@@ -773,7 +784,8 @@ def parseMarkupShorthands(key: str, val: str, lineNum: str | int | None) -> conf
773784
"http",
774785
"idl",
775786
"macros-in-autolinks",
776-
"markdown",
787+
"markdown-block",
788+
"markdown-inline",
777789
"markdown-escapes",
778790
"markup",
779791
"repository-links",
@@ -788,7 +800,13 @@ def parseMarkupShorthands(key: str, val: str, lineNum: str | int | None) -> conf
788800
)
789801
continue
790802
name, boolstring = pieces
791-
if name not in validCategories:
803+
# markdown is an alias for markdown-inline.
804+
# TODO: convert all specs to use markdown-inline, and then turn markdown
805+
# into a shorthand for markdown-*.
806+
if name == "markdown":
807+
name = "markdown-inline"
808+
assert name in validCategories
809+
elif name not in validCategories:
792810
m.die(f"Unknown Markup Shorthand category '{name}'.", lineNum=lineNum)
793811
continue
794812
onoff = boolish(boolstring)

0 commit comments

Comments
 (0)