Skip to content

Commit 76e83b5

Browse files
committed
feat(mdviewer): add h4 and h5 support to block type selector and slash menu
1 parent 5f67ec9 commit 76e83b5

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

src-mdviewer/src/components/editor.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,8 @@ function handleMarkdownShortcutOnSpace(e, contentEl) {
11211121
{ regex: /^#$/, command: "formatBlock", value: "<h1>" },
11221122
{ regex: /^##$/, command: "formatBlock", value: "<h2>" },
11231123
{ regex: /^###$/, command: "formatBlock", value: "<h3>" },
1124+
{ regex: /^####$/, command: "formatBlock", value: "<h4>" },
1125+
{ regex: /^#####$/, command: "formatBlock", value: "<h5>" },
11241126
{ regex: /^[-*]$/, command: "insertUnorderedList" },
11251127
{ regex: /^1\.$/, command: "insertOrderedList" },
11261128
{ regex: /^>$/, command: "formatBlock", value: "<blockquote>" },

src-mdviewer/src/components/embedded-toolbar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ function renderEditMode(level) {
124124
<option value="<h1>">${t("slash.heading1") || "Heading 1"}</option>
125125
<option value="<h2>">${t("slash.heading2") || "Heading 2"}</option>
126126
<option value="<h3>">${t("slash.heading3") || "Heading 3"}</option>
127+
<option value="<h4>">${t("slash.heading4") || "Heading 4"}</option>
128+
<option value="<h5>">${t("slash.heading5") || "Heading 5"}</option>
127129
</select>`;
128130

129131
const textBtns = [
@@ -368,7 +370,7 @@ function updateFormatState(state) {
368370

369371
if (blockTypeSelect && state.blockType) {
370372
const tagToValue = {
371-
"H1": "<h1>", "H2": "<h2>", "H3": "<h3>",
373+
"H1": "<h1>", "H2": "<h2>", "H3": "<h3>", "H4": "<h4>", "H5": "<h5>",
372374
"P": "<p>", "DIV": "<p>"
373375
};
374376
const val = tagToValue[state.blockType] || "<p>";

src-mdviewer/src/components/slash-menu.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
Heading1,
44
Heading2,
55
Heading3,
6+
Heading4,
7+
Heading5,
68
List,
79
ListOrdered,
810
ListChecks,
@@ -37,6 +39,8 @@ const menuItems = [
3739
{ labelKey: "slash.heading1", descKey: "slash.heading1_desc", icon: "heading-1", command: "formatBlock", value: "<h1>" },
3840
{ labelKey: "slash.heading2", descKey: "slash.heading2_desc", icon: "heading-2", command: "formatBlock", value: "<h2>" },
3941
{ labelKey: "slash.heading3", descKey: "slash.heading3_desc", icon: "heading-3", command: "formatBlock", value: "<h3>" },
42+
{ labelKey: "slash.heading4", descKey: "slash.heading4_desc", icon: "heading-4", command: "formatBlock", value: "<h4>" },
43+
{ labelKey: "slash.heading5", descKey: "slash.heading5_desc", icon: "heading-5", command: "formatBlock", value: "<h5>" },
4044
{ labelKey: "slash.bullet_list", descKey: "slash.bullet_list_desc", icon: "list", command: "insertUnorderedList" },
4145
{ labelKey: "slash.numbered_list", descKey: "slash.numbered_list_desc", icon: "list-ordered", command: "insertOrderedList" },
4246
{ labelKey: "slash.task_list", descKey: "slash.task_list_desc", icon: "list-checks", command: "taskList" },
@@ -101,7 +105,7 @@ function getFrecencyScore(id) {
101105
}
102106

103107
const shortcutHints = {
104-
"slash.heading1": "# ", "slash.heading2": "## ", "slash.heading3": "### ",
108+
"slash.heading1": "# ", "slash.heading2": "## ", "slash.heading3": "### ", "slash.heading4": "#### ", "slash.heading5": "##### ",
105109
"slash.bullet_list": "- ", "slash.numbered_list": "1. ",
106110
"slash.task_list": "- [ ] ", "slash.blockquote": "> ",
107111
"slash.code_block": "```", "slash.divider": "---",
@@ -189,7 +193,7 @@ function renderItems() {
189193
menu.innerHTML = html;
190194

191195
createIcons({
192-
icons: { Pilcrow, Heading1, Heading2, Heading3, List, ListOrdered, ListChecks, Quote, FileCode, Table, Minus, Workflow },
196+
icons: { Pilcrow, Heading1, Heading2, Heading3, Heading4, Heading5, List, ListOrdered, ListChecks, Quote, FileCode, Table, Minus, Workflow },
193197
attrs: { class: "" },
194198
});
195199

src-mdviewer/src/locales/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"heading1": "Heading 1",
6060
"heading2": "Heading 2",
6161
"heading3": "Heading 3",
62+
"heading4": "Heading 4",
63+
"heading5": "Heading 5",
6264
"bold": "Bold ({mod}+B)",
6365
"italic": "Italic ({mod}+I)",
6466
"strikethrough": "Strikethrough ({mod}+Shift+X)",
@@ -86,6 +88,10 @@
8688
"heading2_desc": "Medium heading",
8789
"heading3": "Heading 3",
8890
"heading3_desc": "Small heading",
91+
"heading4": "Heading 4",
92+
"heading4_desc": "Smaller heading",
93+
"heading5": "Heading 5",
94+
"heading5_desc": "Smallest heading",
8995
"bullet_list": "Bullet list",
9096
"bullet_list_desc": "Unordered list",
9197
"numbered_list": "Numbered list",

0 commit comments

Comments
 (0)