Skip to content

Commit 1f7a4d7

Browse files
authored
Fix attribute rendering (#1880)
* Fix table row parser Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz> * Remove all `{[command button]}` remnants Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz> * Render `Attribute` nodes in HTML like CodeMirror does This patch - ensures always render `Attribute`, - produces `sb-attribute` span with sub-spans matching CodeMirror DOM, - removee `preserveAttributes` from Markdown render options and callers. Finally the attributes looks the same everywhere (table, text, widget). Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz> --------- Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
1 parent b83c1e0 commit 1f7a4d7

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

client/codemirror/lua_widget.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ export class LuaWidget extends WidgetType {
128128
}
129129
return url;
130130
},
131-
preserveAttributes: true,
132131
},
133132
this.opts.client.ui.viewState.allPages,
134133
);
@@ -265,7 +264,6 @@ export class LuaWidget extends WidgetType {
265264

266265
return url;
267266
},
268-
preserveAttributes: true,
269267
},
270268
this.opts.client.ui.viewState.allPages,
271269
),

client/codemirror/table.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class TableViewWidget extends WidgetType {
7474

7575
return url;
7676
},
77-
preserveAttributes: true,
7877
});
7978
setTimeout(() => {
8079
// Give it a tick to render

client/markdown_renderer/markdown_render.ts

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export type MarkdownRenderOptions = {
2525
failOnUnknown?: true;
2626
smartHardBreak?: true;
2727
annotationPositions?: true;
28-
preserveAttributes?: true;
2928
shortWikiLinks?: boolean;
3029
// When defined, use to inline images as data: urls
3130
translateUrls?: (url: string, type: "link" | "image") => string;
@@ -428,17 +427,48 @@ function render(t: ParseTree, options: MarkdownRenderOptions = {}): Tag | null {
428427
body: cleanTags(mapRender(t.children!), true),
429428
};
430429
}
431-
case "Attribute":
432-
if (options.preserveAttributes) {
433-
return {
434-
name: "span",
435-
attrs: {
436-
class: "attribute",
430+
case "Attribute": {
431+
const nameNode = findNodeOfType(t, "AttributeName");
432+
const valueNode = findNodeOfType(t, "AttributeValue");
433+
const colonNode = findNodeOfType(t, "AttributeColon");
434+
const attrName = nameNode?.children![0].text ?? "";
435+
const attrValue = valueNode?.children![0].text ?? "";
436+
const attrColon = colonNode?.children![0].text ?? ": ";
437+
return {
438+
name: "span",
439+
attrs: {
440+
class: "sb-attribute",
441+
...(attrName ? { [`data-${attrName}`]: attrValue } : {}),
442+
},
443+
body: [
444+
{
445+
name: "span",
446+
attrs: { class: "sb-frontmatter sb-meta" },
447+
body: "[",
437448
},
438-
body: renderToText(t),
439-
};
440-
}
441-
return null;
449+
{
450+
name: "span",
451+
attrs: { class: "sb-frontmatter sb-attribute-name" },
452+
body: attrName,
453+
},
454+
{
455+
name: "span",
456+
attrs: { class: "sb-frontmatter sb-meta" },
457+
body: attrColon,
458+
},
459+
{
460+
name: "span",
461+
attrs: { class: "sb-frontmatter sb-attribute-value" },
462+
body: attrValue,
463+
},
464+
{
465+
name: "span",
466+
attrs: { class: "sb-frontmatter sb-meta" },
467+
body: "]",
468+
},
469+
],
470+
};
471+
}
442472
case "Escape": {
443473
return {
444474
name: "span",

0 commit comments

Comments
 (0)