Add subscript and superscript (#879)

* Added superscript and subscript to markdown

* Added docs for Superscript and subscript

* Remove leftover brace
pull/882/head
MrMugame 2024-06-07 08:21:16 +02:00 committed by GitHub
parent 8524c0f96f
commit 442133ea2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 40 additions and 6 deletions

View File

@ -29,3 +29,6 @@ export const NakedURLTag = Tag.define();
export const DirectiveMarkTag = Tag.define(); export const DirectiveMarkTag = Tag.define();
export const DirectiveTag = Tag.define(); export const DirectiveTag = Tag.define();
export const SubscriptTag = Tag.define();
export const SuperscriptTag = Tag.define();

View File

@ -8,6 +8,8 @@ import {
Line, Line,
MarkdownConfig, MarkdownConfig,
Strikethrough, Strikethrough,
Subscript,
Superscript,
} from "@lezer/markdown"; } from "@lezer/markdown";
import { markdown } from "@codemirror/lang-markdown"; import { markdown } from "@codemirror/lang-markdown";
import { StreamLanguage } from "@codemirror/language"; import { StreamLanguage } from "@codemirror/language";
@ -624,6 +626,8 @@ export const extendedMarkdownLanguage = markdown({
Hashtag, Hashtag,
TaskDeadline, TaskDeadline,
NamedAnchor, NamedAnchor,
Superscript,
Subscript,
{ {
props: [ props: [
foldNodeProp.add({ foldNodeProp.add({
@ -646,8 +650,9 @@ export const extendedMarkdownLanguage = markdown({
Task: ct.TaskTag, Task: ct.TaskTag,
TaskMark: ct.TaskMarkTag, TaskMark: ct.TaskMarkTag,
Comment: ct.CommentTag, Comment: ct.CommentTag,
"TableDelimiter SubscriptMark SuperscriptMark StrikethroughMark": "Subscript": ct.SubscriptTag,
t.processingInstruction, "Superscript": ct.SuperscriptTag,
"TableDelimiter StrikethroughMark": t.processingInstruction,
"TableHeader/...": t.heading, "TableHeader/...": t.heading,
TableCell: t.content, TableCell: t.content,
CodeInfo: ct.CodeInfoTag, CodeInfo: ct.CodeInfoTag,

View File

@ -477,6 +477,16 @@ function render(
body: renderToText(t), body: renderToText(t),
}; };
} }
case "Superscript":
return {
name: "sup",
body: cleanTags(mapRender(t.children!)),
};
case "Subscript":
return {
name: "sub",
body: cleanTags(mapRender(t.children!)),
};
// Text // Text
case undefined: case undefined:

View File

@ -21,6 +21,8 @@ const typesWithMarks = [
"InlineCode", "InlineCode",
"Highlight", "Highlight",
"Strikethrough", "Strikethrough",
"Superscript",
"Subscript",
]; ];
/** /**
* The elements which are used as marks. * The elements which are used as marks.
@ -30,6 +32,8 @@ const markTypes = [
"CodeMark", "CodeMark",
"HighlightMark", "HighlightMark",
"StrikethroughMark", "StrikethroughMark",
"SuperscriptMark",
"SubscriptMark",
]; ];
/** /**

View File

@ -53,6 +53,8 @@ export default function highlightStyles() {
{ tag: ct.NakedURLTag, class: "sb-naked-url" }, { tag: ct.NakedURLTag, class: "sb-naked-url" },
{ tag: ct.TaskDeadlineTag, class: "sb-task-deadline" }, { tag: ct.TaskDeadlineTag, class: "sb-task-deadline" },
{ tag: ct.NamedAnchorTag, class: "sb-named-anchor" }, { tag: ct.NamedAnchorTag, class: "sb-named-anchor" },
{ tag: ct.SubscriptTag, class: "sb-sub" },
{ tag: ct.SuperscriptTag, class: "sb-sup" },
{ tag: ct.DirectiveMarkTag, class: "sb-directive-mark" }, { tag: ct.DirectiveMarkTag, class: "sb-directive-mark" },
{ tag: ct.DirectiveTag, class: "sb-directive" }, { tag: ct.DirectiveTag, class: "sb-directive" },

View File

@ -218,9 +218,9 @@
.sb-line-h3 .sb-meta, .sb-line-h3 .sb-meta,
.sb-line-h4 .sb-meta, .sb-line-h4 .sb-meta,
.sb-line-h5 .sb-meta, .sb-line-h5 .sb-meta,
.sb-line-h6 .sb-meta, .sb-line-h6 .sb-meta {
{ color: var(--editor-heading-meta-color);
color: var(--editor-heading-meta-color); }
} }
.sb-hashtag, .sb-hashtag,
@ -386,6 +386,16 @@ tbody tr:nth-of-type(even) {
font-weight: 900; font-weight: 900;
} }
.sb-sub {
vertical-align: sub;
font-size: smaller;
}
.sb-sup {
vertical-align: super;
font-size: smaller;
}
.sb-line-code-outside .sb-code-info { .sb-line-code-outside .sb-code-info {
color: var(--editor-code-info-color); color: var(--editor-code-info-color);
} }
@ -432,5 +442,4 @@ a.sb-wiki-link-page-missing,
.sb-line-comment { .sb-line-comment {
background-color: var(--editor-code-comment-color); // rgba(255, 255, 0, 0.5); background-color: var(--editor-code-comment-color); // rgba(255, 255, 0, 0.5);
}
} }

View File

@ -15,4 +15,5 @@ In addition to supporting [[Markdown/Basics|markdown basics]] as standardized by
* [Task lists](https://www.markdownguide.org/extended-syntax/#task-lists) * [Task lists](https://www.markdownguide.org/extended-syntax/#task-lists)
* [Highlight](https://www.markdownguide.org/extended-syntax/#highlight) * [Highlight](https://www.markdownguide.org/extended-syntax/#highlight)
* [Automatic URL linking](https://www.markdownguide.org/extended-syntax/#automatic-url-linking) * [Automatic URL linking](https://www.markdownguide.org/extended-syntax/#automatic-url-linking)
* [Subscript](https://www.markdownguide.org/extended-syntax/#subscript) and [superscript](https://www.markdownguide.org/extended-syntax/#superscript)
* Any addition custom markdown extensions provided by [[Plugs]] * Any addition custom markdown extensions provided by [[Plugs]]