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

vue-docgen-cli: Template util mdclean, escape arrow brackets in code #1623

Open
Kolobok12309 opened this issue Nov 9, 2023 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@Kolobok12309
Copy link
Contributor

Current behavior

mdclean helper disable feature of markdown for using <> symbols in code blocks

export function mdclean(input: string): string {
if (typeof input !== 'string') {
return `${input}`
}
return input
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\|/g, '\\|')
.replace(/\r?\n/g, '<br/>')
}

// Input
Some info about `<input>`

Output: &lt;input&gt;
Expected: <input>

Expected behavior

Escape <> only outside quotes

@elevatebart elevatebart added the enhancement New feature or request label Nov 9, 2023
@elevatebart elevatebart added this to To Do in vue-docgen-cli via automation Nov 9, 2023
@elevatebart
Copy link
Member

hello @Kolobok12309 ,

Thank you for your request.
What you describe would be ideal indeed.

Do you have any idea how to do that?

Here is a rough idea, but I wonder if it will work:

  • Tokenize on various quote marks
  • Loop through the strings (tokens) obtained and replace the non-quoted tokens
  • Re-join all of it using their original quotemarks.

Beyond making the code more complicated, do you think we will lose some performance?

@Kolobok12309
Copy link
Contributor Author

Do you have any idea how to do that?

Mb something like this, but need testing and some cases mb not worked

string
  .split('`')
  .map((str, index) => 
    index % 2
       ? str
       : str
          .replace(/</g, '&lt;') 
          .replace(/>/g, '&gt;') 
  )
  .join('`')

Beyond making the code more complicated, do you think we will lose some performance?

Yea, it's not so good. Mb need do it through some func args.

Why <> escaped?

@elevatebart
Copy link
Member

The html markers are escaped because if used in a md table they will break the table (except, it seems, between quote marks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
vue-docgen-cli
  
To Do
Development

No branches or pull requests

2 participants