showdownjs/showdown

Auto-linking @mention from HTML to Markdown

开放

#910 创建于 2022年4月6日

 (2 条评论) (0 个反应) (1 位负责人)JavaScript (1,640 个派生)batch import
enhancementhelp wanted

仓库指标

星标
 (13,700 个星标)
PR 合并指标
 (平均合并 15小时 21分钟) (30 天内合并 3 个 PR)

描述

I've created an editor in which the User can switch between a Rich Text version (Quill.js, if it matters) and Markdown and, in a Babel class, I've set up the Showdown like this:

this.showdown = new showdown.Converter({
  omitExtraWLInCodeBlocks: false,
  noHeaderId: true,
  simplifiedAutoLink: true,
  excludeTrailingPunctuationFromURLs: true,
  literalMidWordUnderscores: true,
  strikethrough: true,
  tables: false,
  ghCodeBlocks: true,
  tasklists: true,
  ghMentions: true,
  ghMentionsLink: '/perfil/?user={u}',
  smartIndentationFix: true,
  disableForced4SpacesIndentedSublists: true,
  simpleLineBreaks: false,
  requireSpaceBeforeHeadingText: true,
  encodeEmails: true
});

this.showdown.setFlavor( 'github' );

When conditions are met (i.e. the editor toggler is clicked) to parse the HTML from the Rich Text into the Markdown <textarea>, I have this:

return this.showdown.makeMarkdown( html );

And from Markdown to HTML, I have this:

return this.showdown.makeHtml( text );

text and html are method arguments to represent, as implied, Quill's HTML and Markdown Text

The problem I'm experiencing is that when converting to HTML it works perfectly, and I receive in my Quill Editor the <a> tag, but when going for Markdown I don't receive the (I suppose) [text](link) syntax.

I've isolated the code, out of my Quill implementation:

var showdown = new showdown.Converter({
  omitExtraWLInCodeBlocks: false,
  noHeaderId: true,
  simplifiedAutoLink: true,
  excludeTrailingPunctuationFromURLs: true,
  literalMidWordUnderscores: true,
  strikethrough: true,
  tables: false,
  ghCodeBlocks: true,
  tasklists: true,
  ghMentions: true,
  ghMentionsLink: '/perfil/?user={u}',
  smartIndentationFix: true,
  disableForced4SpacesIndentedSublists: true,
  simpleLineBreaks: false,
  requireSpaceBeforeHeadingText: true,
  encodeEmails: true
});

showdown.setFlavor( 'github' );

function toMarkdown( html ) {
  return showdown.makeMarkdown( html );
}

function toRichText( text ) {
  return showdown.makeHtml( text );
}

console.log( toRichText( '@brunoaugusto' ) );
console.log( toMarkdown( '@brunoaugusto' ) );

And the results were the same. That said, will Showdown not convert, for example, <p>@brunoaugusto</p> into [/perfil/?user=brunoaugusto](@brunoaugusto) or I've implemented the routine wrongly?

贡献者指南