Skip to content

[😁 Resolved]How to write a custom syntax plugin to parse ==highlight_content== to <mark>highlight_content</mark>? #1674

Answered by yswang0927
yswang0927 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @Saul-Mirone

I wrote it, it works ok now 😁, thank you very much 🤝🤝

import { $inputRule, $node, $remark } from '@milkdown/kit/utils';
import { InputRule } from '@milkdown/kit/prose/inputrules';

/**
 * custom-syntax-plugin: Parse `==content==` to `<mark>content</mark>`
 */
const remarkMark = $remark('remarkMark', () => () => (tree) => {
    const visit = (node) => {
        // only parse text node
        if (node.type === 'text' && typeof node.value === 'string') {
            const value = node.value;
            const regex = /==([^=]+)==/g;
            let match;
            let lastIndex = 0;
            const nodes = [];

            while ((match = regex.exec(value)) !== null) {

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@yswang0927
Comment options

@Saul-Mirone
Comment options

@yswang0927
Comment options

@Saul-Mirone
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by yswang0927
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants