Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the result of lex a markdown text, which contains blockquote, contains a \n #3036

Closed
tzq0301 opened this issue Oct 12, 2023 · 3 comments · Fixed by #3037
Closed

the result of lex a markdown text, which contains blockquote, contains a \n #3036

tzq0301 opened this issue Oct 12, 2023 · 3 comments · Fixed by #3037

Comments

@tzq0301
Copy link

tzq0301 commented Oct 12, 2023

Marked version: ^9.1.1

Describe the bug

the result of lex a markdown text, which contains blockquote, contains a \n

To Reproduce

import {marked} from "marked";

const lexer = new marked.Lexer();

const tokens = lexer.lex(`
# Hello World

> Preface

say sth.

## 1. One

1111

## 2. Two

2222
`)
    .filter(token => token.type !== 'space')
    .map(token => {
        return {
            type: token.type,
            text: token.text,
        };
    });

console.log(tokens);

the output is:

[
  { type: 'heading', text: 'Hello World' },
  { type: 'blockquote', text: 'Preface\n' },
  { type: 'paragraph', text: 'say sth.' },
  { type: 'heading', text: '1. One' },
  { type: 'paragraph', text: '1111' },
  { type: 'heading', text: '2. Two' },
  { type: 'paragraph', text: '2222' }
]

Expected behavior

my expected output is:

[
  { type: 'heading', text: 'Hello World' },
  { type: 'blockquote', text: 'Preface' },    // <- here, expect no '\n\
  { type: 'paragraph', text: 'say sth.' },
  { type: 'heading', text: '1. One' },
  { type: 'paragraph', text: '1111' },
  { type: 'heading', text: '2. Two' },
  { type: 'paragraph', text: '2222' }
]
@UziTech
Copy link
Member

UziTech commented Oct 12, 2023

I think that sounds reasonable to trim the text. If you want to create a PR I would approve it.

@tzq0301
Copy link
Author

tzq0301 commented Oct 13, 2023

@UziTech I probably won’t be able to do this PR because I don’t know much about javascript

@UziTech
Copy link
Member

UziTech commented Oct 13, 2023

I created PR #3037 to fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants