Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ pnpm-lock.yaml

**/translations.json
/CHANGELOG.md

# markdown round trip fixtures, formatting is part of the test
packages/web-pkg/tests/unit/editor/strategies/fixtures/
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ export const useStrategyMarkdown = (editorState: TextEditorState): ContentTypeSt
// process wide singleton which grows with every editor opened and keeps each
// manager it ever saw alive. Holding our own instance bounds both to the
// lifetime of this strategy.
const instance = new Marked()
registerFrontmatterTokenizer(instance)
registerMarkdownListTokenizer(instance)
// Cast because tiptap types the option as the default export, which carries a
// `getDefaults` helper a plain instance lacks. The manager never calls it: it
// only touches `use`, `setOptions`, `Lexer`, `lexer` and `defaults`.
const marked = new Marked() as unknown as typeof markedDefault
registerFrontmatterTokenizer(marked)
registerMarkdownListTokenizer(marked)
const marked = instance as unknown as typeof markedDefault

const editorContentType = () => {
return 'markdown'
Expand Down
4 changes: 2 additions & 2 deletions packages/web-pkg/src/editor/extensions/frontmatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { commands as coreCommands, Node, mergeAttributes } from '@tiptap/core'
import type { CommandProps, JSONContent, MarkdownToken } from '@tiptap/core'
import type { marked } from 'marked'
import type { Marked } from 'marked'
import { TextSelection } from '@tiptap/pm/state'
import { VueNodeViewRenderer } from '@tiptap/vue-3'
import FrontmatterComponent from '../components/FrontmatterComponent.vue'
Expand Down Expand Up @@ -45,7 +45,7 @@ const frontmatterPattern = /^---[ \t]*\r?\n([\s\S]*?)(?:\r?\n)?---[ \t]*(?:\r?\n
* given and never removes them, so the singleton would grow for as long as the
* tab is open and hold on to every manager it ever saw.
*/
export function registerFrontmatterTokenizer(instance: typeof marked): void {
export function registerFrontmatterTokenizer(instance: Marked): void {
instance.use({
extensions: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/web-pkg/src/editor/extensions/markdownLists.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { JSONContent, MarkdownToken } from '@tiptap/core'
import { ListItem, OrderedList } from '@tiptap/extension-list'
import { Tokenizer } from 'marked'
import type { marked } from 'marked'
import type { Marked } from 'marked'

function isEmptySubItemUnderline(token?: MarkdownToken): boolean {
// `- text` followed by ` -` lexes as a setext heading, not as an empty sub item
Expand Down Expand Up @@ -118,7 +118,7 @@ const emptyFirstItemPattern = /^( {0,3}(?:[-+*]|\d{1,9}[.)]))[ \t]+(?=\n|$)/
*
* Takes the instance as an argument for the same reason as `registerFrontmatterTokenizer`.
*/
export function registerMarkdownListTokenizer(instance: typeof marked): void {
export function registerMarkdownListTokenizer(instance: Marked): void {
instance.use({
tokenizer: {
list(src) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Fixtures
tags: [a, b]
---

# Heading 1

## Heading 2

Setext heading
==============

Text with *emphasis*, __strong__, ~~strike~~, `code` and a [link](https://opencloud.eu "title").
A second line with a hard break
after it.

![image](https://opencloud.eu/logo.png)

> A quote
> with two lines
>
> > nested

***

* bullet
* list
+ nested

1. ordered
2. list

- [ ] open task
- [x] done task

| left | center | right |
|:-----|:------:|------:|
| a | b | c |
| `d` | **e** | [f](#f) |

```js
const x = 1
```

indented code
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Fixtures
tags: [a, b]
---

# Heading 1

## Heading 2

# Setext heading

Text with *emphasis*, **strong**, ~~strike~~, `code` and a [link](https://opencloud.eu "title").
A second line with a hard break
after it.

![image](https://opencloud.eu/logo.png)

> A quote
> with two lines
>
> > nested

---

- bullet
- list
- nested

1. ordered
2. list

- [ ] open task
- [x] done task


| left | center | right |
| :---- | :------: | -------: |
| a | b | c |
| `d` | **e** | [f](#f) |


```js
const x = 1
```

```
indented code
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> [!NOTE]
> hint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> \[!NOTE\](x) text

> \[!NOTE\] text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```
code
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```
code
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```
code
x
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```
code
x
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- a
```
code
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- a

```
code
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* a
* b
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- a
- b
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- > quote
- b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-  
> quote
- b
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-
- b
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-
- b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- a
1.
2. b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- a
1.  
2. b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> -
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> -
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-
- x
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-  
- x
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- a
-
- b

1.
2. b
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- a
-
- b

1.
2. b
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. a
2.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. a
2.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- a
- b
-
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- a
- b
-
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- Parent
-  
- x
- c

- a
-  
- x
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Parent
-  
- x
- c
- a
-  
- x
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- Parent
-  
- c
- Next

1. Parent
-  
- c
2. Next
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- a
2\. b
Dr\. Smith
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- a
2\. b
Dr\. Smith
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-
# Title
- b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-  
# Title
- b
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- # Title
- b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-  
# Title
- b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a.
# Title
b. y
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a.  
# Title
b. y
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. # Title
2. b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.  
# Title
2. b
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- a

![a](http://x/a.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- ![a](http://x/a.png)
- sub
- a
- ![b](http://x/b.png)

1. ![c](http://x/c.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1. \-
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a. one
b.
c. three
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a. one
b.  
c. three
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-  

text

-  
- x

a.  
b. two
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a. one
b. two
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
i. one
ii. two
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1. a

more
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1. a

more
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. a
b
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. a
b
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1. a
12345678901\. b
2. a
B\. b
3. a
2\. b
4. a
\- b
5. a
\# b
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1. a
12345678901\. b
2. a
B\. b
3. a
2\. b
4. a
\- b
5. a
\# b
Loading
Loading