Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b76bd86

Browse files
committedDec 23, 2023
fix: indent ordered list
1 parent e1fe88e commit b76bd86

File tree

6 files changed

+38
-18
lines changed

6 files changed

+38
-18
lines changed
 

‎sandbox/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<MarkdownUi
88
v-model="content"
99
:editable="editable"
10-
mode="read"
10+
mode="split"
1111
theme="light"
1212
@cancel="cancelEdit"
1313
@mode="modeChanged"

‎sandbox/mock-document-response.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
22
id: 'da315607-4d04-4a54-810d-45156b575932',
3-
content: "# Markdown UI\n\nA markdown renderer and edit UI.\n\n## Formatting types\n\n### Code block and inline code\n\n```typescript\n// TODO: Fenced code blocks need default styles\nconst name = 'Adam'\n```\n\nThis sentence has \\`inlineCode\\` in the middle.\n\n### Emoji\n\n:smile: :rocket: :tada:\n\n### Link\n\n[link](https://github.com)\n\n### Tables\n\n| Column1 | Column2 | Column3 |\n| :--- | :--- | :--- |\n| Content | Content | Content |\n\n### Todo items\n\n- [x] Todo item checked\n- [ ] Another item not checked\n\n---\n\n### Diagrams\n\n#### Mermaid\n\n```mermaid\ngitGraph\n commit\n commit\n branch develop\n checkout develop\n commit\n commit\n checkout main\n merge develop\n commit\n commit\n```\n\n#### Plantuml\n\n```plantuml\nBob -> Alice : hello\n```\n\n#### DOT\n\n```dot\ndigraph example1 {\n 1 -> 2 -> { 4, 5 };\n 1 -> 3 -> { 6, 7 };\n}\n```\n",
3+
content: "# Markdown UI\n\nA markdown renderer and edit UI.\n\n## Formatting types\n\n### Code block and inline code\n\n```typescript\n// TODO: Fenced code blocks need default styles\nconst name = 'Adam'\n```\n\nThis sentence has `inlineCode` in the middle.\n\n### Emoji\n\n:smile: :rocket: :tada:\n\n### Link\n\n[link](https://github.com)\n\n### Tables\n\n| Column1 | Column2 | Column3 |\n| :--- | :--- | :--- |\n| Content | Content | Content |\n\n### Todo items\n\n- [x] Todo item checked\n- [ ] Another item not checked\n\n---\n\n### Diagrams\n\n#### Mermaid\n\n```mermaid\ngitGraph\n commit\n commit\n branch develop\n checkout develop\n commit\n commit\n checkout main\n merge develop\n commit\n commit\n```\n\n#### Plantuml\n\n```plantuml\nBob -> Alice : hello\n```\n\n#### DOT\n\n```dot\ndigraph example1 {\n 1 -> 2 -> { 4, 5 };\n 1 -> 3 -> { 6, 7 };\n}\n```\n",
44
parent_document_id: null,
55
slug: 'markdown',
66
title: 'markdown',

‎src/components/MarkdownContent.vue

+12-8
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ $header-anchor-offset-top: calc(var(--kui-space-50, $kui-space-50) + 2px);
9191
font-family: var(--kui-font-family-code, $kui-font-family-code);
9292
}
9393
94-
// code blocks
95-
pre,
96-
code {
97-
white-space: pre;
98-
// width: 100%;
99-
word-break: normal;
100-
word-spacing: normal;
101-
word-wrap: normal;
94+
// Inline code within the content area
95+
p code {
96+
background: var(--kui-color-background-neutral-weaker, $kui-color-background-neutral-weaker);
97+
border-radius: var(--kui-border-radius-20, $kui-border-radius-20);
98+
font-size: var(--kui-font-size-30, $kui-font-size-30);
99+
padding: var(--kui-space-10, $kui-space-10) var(--kui-space-20, $kui-space-20);
100+
white-space: break-spaces;
101+
word-wrap: break-word;
102102
}
103103
104104
pre {
@@ -111,6 +111,10 @@ $header-anchor-offset-top: calc(var(--kui-space-50, $kui-space-50) + 2px);
111111
overflow-wrap: break-word;
112112
overflow-x: auto;
113113
padding: var(--kui-space-70, $kui-space-70);
114+
white-space: pre;
115+
word-break: normal;
116+
word-spacing: normal;
117+
word-wrap: normal;
114118
}
115119
116120
// Styles for fenced code block copy button in `src/composables/useMarkdownIt.ts`

‎src/components/MarkdownUi.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ const props = defineProps({
8888
/** The number of spaces to insert on tab. Defaults to 2, max of 10 */
8989
tabSize: {
9090
type: Number,
91-
default: 2,
92-
validator: (size: number): boolean => size >= 2 && size <= 10,
91+
default: 4,
92+
validator: (size: number): boolean => size >= 2 && size <= 6,
9393
},
9494
/** MermaidJs is heavy; allow it opting-out by passing false. Defaults to true. */
9595
mermaid: {

‎src/components/toolbar/MarkdownToolbar.vue

+6-3
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,12 @@ const formatOptions: FormatOption[] = [
235235
{ label: 'Italic', action: 'italic', keys: ['I'], icon: ItalicIcon },
236236
{ label: 'Underline', action: 'underline', keys: ['U'], icon: UnderlineIcon },
237237
{ label: 'Strikethrough', action: 'strikethrough', keys: ['Shift', 'X'], icon: StrikethroughIcon },
238-
{ label: 'Subscript', action: 'subscript', icon: SubscriptIcon },
239-
{ label: 'Superscript', action: 'superscript', icon: SuperscriptIcon },
240-
{ label: 'Mark', action: 'mark', icon: MarkIcon },
238+
// Hidden for now
239+
// { label: 'Subscript', action: 'subscript', icon: SubscriptIcon },
240+
// Hidden for now
241+
// { label: 'Superscript', action: 'superscript', icon: SuperscriptIcon },
242+
// Hidden for now
243+
// { label: 'Mark', action: 'mark', icon: MarkIcon },
241244
{ label: 'Code', action: 'code', keys: ['Shift', 'C'], icon: CodeIcon },
242245
]
243246

‎src/composables/useMarkdownActions.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,14 @@ export default function useMarkdownActions(
222222
const startText = rawMarkdown.value.substring(0, selectedText.start)
223223

224224
// When removing tabs, ensure string starts with two spaces; or a list item that is already indented. If not, exit
225-
if (action === 'remove' && (!startText.endsWith(spaces) && !startText.endsWith(' ' + MARKDOWN_TEMPLATE_UL))) {
225+
if (
226+
action === 'remove' &&
227+
!startText.endsWith(spaces) &&
228+
// Not an unordered list
229+
!startText.endsWith(' ' + MARKDOWN_TEMPLATE_UL) &&
230+
// Not an ordered list
231+
!/ {2}\d{1,}\. $/.test(startText)
232+
) {
226233
return
227234
}
228235

@@ -241,8 +248,14 @@ export default function useMarkdownActions(
241248
// If text starts with an inline template
242249
if (startText.endsWith(MARKDOWN_TEMPLATE_UL)) {
243250
rawMarkdown.value = action === 'add' ? rawMarkdown.value.substring(0, selectedText.start - MARKDOWN_TEMPLATE_UL.length) + spaces + MARKDOWN_TEMPLATE_UL + rawMarkdown.value.substring(selectedText.end) : rawMarkdown.value.substring(0, selectedText.start - spaces.length - MARKDOWN_TEMPLATE_UL.length) + MARKDOWN_TEMPLATE_UL + rawMarkdown.value.substring(selectedText.end)
244-
} else if (startText.endsWith(MARKDOWN_TEMPLATE_OL)) {
245-
rawMarkdown.value = action === 'add' ? rawMarkdown.value.substring(0, selectedText.start - MARKDOWN_TEMPLATE_OL.length) + spaces + MARKDOWN_TEMPLATE_OL + rawMarkdown.value.substring(selectedText.end) : rawMarkdown.value.substring(0, selectedText.start - spaces.length - MARKDOWN_TEMPLATE_OL.length) + MARKDOWN_TEMPLATE_OL + rawMarkdown.value.substring(selectedText.end)
251+
} else if (/\d{1,}\. $/.test(startText.split(NEW_LINE_CHARACTER).pop() || '')) {
252+
// Remove the `1` in the ordered list template
253+
const numberSuffix = MARKDOWN_TEMPLATE_OL.replace('1', '')
254+
255+
const listNumber = Number((startText.split(NEW_LINE_CHARACTER).at(-2) || startText.split(NEW_LINE_CHARACTER).pop() || '').trimStart().split(numberSuffix)[0]) + 1
256+
console.log('listNumber', listNumber)
257+
258+
rawMarkdown.value = action === 'add' ? rawMarkdown.value.substring(0, selectedText.start - MARKDOWN_TEMPLATE_OL.length) + spaces + MARKDOWN_TEMPLATE_OL + rawMarkdown.value.substring(selectedText.end) : rawMarkdown.value.substring(0, selectedText.start - spaces.length - (listNumber + numberSuffix).length) + (listNumber + numberSuffix) + rawMarkdown.value.substring(selectedText.end)
246259
} else {
247260
rawMarkdown.value = action === 'add' ? startText + spaces + rawMarkdown.value.substring(selectedText.end) : rawMarkdown.value.substring(0, selectedText.start - spaces.length) + rawMarkdown.value.substring(selectedText.end)
248261
}

0 commit comments

Comments
 (0)
Please sign in to comment.