Giter Site home page Giter Site logo

ts-stack / markdown Goto Github PK

View Code? Open in Web Editor NEW
128.0 128.0 27.0 1013 KB

A full-featured markdown parser and compiler, written in TypeScript.

JavaScript 1.21% TypeScript 37.16% HTML 61.63%
gfm javascript markdown markdown-flavors markdown-parser typescript

markdown's People

Contributors

dependabot[bot] avatar habc0807 avatar kostyatretyak avatar mvanassche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdown's Issues

There is an error when trying to pass options as `parse` argument

let options: MarkedOptions = {isNoP: true};

Marked.setOptions(options);//is working but

Marked.parse("some intput", options)//provides to error:

TypeError: this.options.escape is not a function
Please report this to https://github.com/KostyaTretyak/marked-ts
    at InlineLexer.output (http://localhost:8100/build/vendor.js:74738:56)
    at Parser.parseText (http://localhost:8100/build/vendor.js:74372:33)
    at Parser.tok (http://localhost:8100/build/vendor.js:74387:37)
    at Parser.parse (http://localhost:8100/build/vendor.js:74345:25)
    at Function.Parser.parse (http://localhost:8100/build/vendor.js:74338:23)
    at Function.Marked.callParser (http://localhost:8100/build/vendor.js:50612:36)
    at Function.Marked.parse (http://localhost:8100/build/vendor.js:50558:25)
    at MarkedProvider.webpackJsonp.214.MarkedProvider.simpleMarked (http://localhost:8100/build/main.js:162:66)
....

IE 11 issue on 1.0.0-beta.5

Hello,

The latest versjon of markdown-ts has issue with polyfills.

Issue is in this line

Object.assign(this.options, options);

Describe the bug

The latest version or 1.0.0-beta.5 does not work in IE 11

To Reproduce

Import it in any file and open this one in IE 11

Expected behavior

It works :) .

Escaping `{` into `{{ '{' }}`?

Nice work with marked-ts!


Wrote a little script to allow Angular to support Markdown, using marked-ts.

Given b.component.md:

## Hello
<div *ngIf="true">
```bash
echo ${5}
```
</div>

It generates:

<h2 id="hello">Hello</h2>
<div *ngIf="true">
<code>bash
echo ${5}</code>
</div>

How would I escape things Angular doesn't support?

Namely, I want to generate:

<h2 id="hello">Hello</h2>
<div *ngIf="true">
<code>bash
echo ${{'{'}}5{{'}'}}</code>
</div>

EDIT_0: I can't escape with NgNonBindable due to angular/angular#11859
EDIT_1: Wrote a very basic custom post processing for this:
https://github.com/SamuelMarks/ng-md-components/blob/ceec9783881a2864fe5e2fff82bec115895733de/index.ts#L73-L91

A way skip initial <P> tag?

First; Thank you for a wonderful Markdown parser!

When using it inside React I think i have to insert generated markup like this

return <div dangerouslySetInnerHTML={{ __html: Marked.parse(markup) }} />

Please advice me if I'm wrong. But then I get this error from React:

Warning: validateDOMNesting(...): <p> cannot appear as a descendant of <div>.

Is there a way to skip the surrounding p-tag generated by the parser ?

this.options.escape is not a function

Received an error while trying some more complicated markdown rendering.

Message: this.options.escape is not a function Please report this to https://github.com/KostyaTretyak/marked-ts
Exception type: TypeError
Failed method: Renderer.code

Stack:

TypeError:
   at Renderer.code (at Renderer.code (/home/site/wwwroot/dist/server.js:78487:69)at Renderer.code (/home/site/wwwroot/dist/server.js:78487:69): /home/site/wwwroot/dist/server.jsat Renderer.code (/home/site/wwwroot/dist/server.js:78487:69): 78487)
   at Parser.tok (at Parser.tok (/home/site/wwwroot/dist/server.js:78392:42)at Parser.tok (/home/site/wwwroot/dist/server.js:78392:42): /home/site/wwwroot/dist/server.jsat Parser.tok (/home/site/wwwroot/dist/server.js:78392:42): 78392)
   at Parser.parse (at Parser.parse (/home/site/wwwroot/dist/server.js:78314:25)at Parser.parse (/home/site/wwwroot/dist/server.js:78314:25): /home/site/wwwroot/dist/server.jsat Parser.parse (/home/site/wwwroot/dist/server.js:78314:25): 78314)
   at Function.Parser.parse (at Function.Parser.parse (/home/site/wwwroot/dist/server.js:78307:23)at Function.Parser.parse (/home/site/wwwroot/dist/server.js:78307:23): /home/site/wwwroot/dist/server.jsat Function.Parser.parse (/home/site/wwwroot/dist/server.js:78307:23): 78307)
   at Function.Marked.callParser (at Function.Marked.callParser (/home/site/wwwroot/dist/server.js:78256:36)at Function.Marked.callParser (/home/site/wwwroot/dist/server.js:78256:36): /home/site/wwwroot/dist/server.jsat Function.Marked.callParser (/home/site/wwwroot/dist/server.js:78256:36): 78256)
   at Function.Marked.parse (at Function.Marked.parse (/home/site/wwwroot/dist/server.js:78202:25)at Function.Marked.parse (/home/site/wwwroot/dist/server.js:78202:25): /home/site/wwwroot/dist/server.jsat Function.Marked.parse (/home/site/wwwroot/dist/server.js:78202:25): 78202)
   at renderMarkdown (at renderMarkdown (/home/site/wwwroot/dist/server.js:77732:61)at renderMarkdown (/home/site/wwwroot/dist/server.js:77732:61): /home/site/wwwroot/dist/server.jsat renderMarkdown (/home/site/wwwroot/dist/server.js:77732:61): 77732)
   at contentSection.item.data.contentSection.item.data.contentSection.map.section (at contentSection.item.data.contentSection.item.data.contentSection.map.section (/home/site/wwwroot/dist/server.js:79220:116)at contentSection.item.data.contentSection.item.data.contentSection.map.section (/home/site/wwwroot/dist/server.js:79220:116): /home/site/wwwroot/dist/server.jsat contentSection.item.data.contentSection.item.data.contentSection.map.section (/home/site/wwwroot/dist/server.js:79220:116): 79220)
   at mapCommunicationArticle (at mapCommunicationArticle (/home/site/wwwroot/dist/server.js:79217:77)at mapCommunicationArticle (/home/site/wwwroot/dist/server.js:79217:77): /home/site/wwwroot/dist/server.jsat mapCommunicationArticle (/home/site/wwwroot/dist/server.js:79217:77): 79217)

The offending markdown (but with three backticks):

`` 
{
  "firstName": "John",
  "lastName": "Smith",
  "age": 25
}
`` 

identity parsing for markdown transformation

Problem

This library takes md as input and parse more-or-less creates HTML, but I expected a parsed IR of the markdown, versus a transformed format. parse seems to actually be convert, vs parse.

I need to take md => md, but adding content along the way.

Can this library support that use case?

Issue using {sanitize:true} inline

Using following way to sanitize causes runtime error.

     {@html Marked.parse(event.description ?? '', {sanitize: true})}

TypeError: this.options.escape is not a function
Please report this to https://github.com/ts-stack/markdown
at InlineLexer.output (/Users/xxxx/node_modules/@ts-stack/markdown/bundles/ts-stack-markdown.umd.js:797:60)
at Parser.tok (/Users/xxxx/node_modules/@ts-stack/markdown/bundles/ts-stack-markdown.umd.js:930:69)
at Parser.parse (/Users/xxxx/node_modules/@ts-stack/markdown/bundles/ts-stack-markdown.umd.js:894:29)
at Parser.parse (/Users/xxxx/node_modules/@ts-stack/markdown/bundles/ts-stack-markdown.umd.js:887:27)
at Marked.callParser (/Users/xxxx/node_modules/@ts-stack/markdown/bundles/ts-stack-markdown.umd.js:1137:31)
at Marked.parse (/Users/xxxx/node_modules/@ts-stack/markdown/bundles/ts-stack-markdown.umd.js:1078:29)
at eval (/Users/xxxx/src/lib/components/EventCard.svelte:29:1006)
at Object.$$render (/Users/xxxx/node_modules/svelte/src/runtime/internal/ssr.js:174:16)
at Object.default (/Users/xxxx/src/routes/(prerender)/(home)/+page.svelte:93:102)
at eval (/Users/xxxx/src/lib/components/Section.svelte:17:39)

Detect code block vs code snippet

How can I detect if it was a tripple backtick codeblock or a single backtick code snippet in renderer?

class MarkdownRenderer extends Renderer {
    code(code: string, lang: string, escaped: boolean) {
        if (escaped) return code
        return `<pre><code class="codeblock lang-${lang}">${code}</code></pre>`
    }
}

How to get `hljs` class on code element?

When using with highlightjs the resulting <code> element should have the hljs class as well as lang-whatever in order to properly theme the code with background color etc.

Is there an easy way to configure marked-ts to do this automatically?

Add option for line break ('<br>') character

I would like to use a backslash \ instead of double spaces to render a line break, maybe this could be an option in the settings - or is it possible somehow to change the regex for a line break?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.