How to use marked - 10 common examples

To help you get started, we’ve selected a few marked examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github influxdata / clockface / src / Components / IndexList / Documentation / IndexList.stories.tsx View on Github external
`Header clicked! nextSort: ${nextSort}, sortKey: ${sortKey}`
                  )
                }
              />
            
          
        
        <div>
          <button>Log Ref</button>
        </div>
      
    )
  },
  {
    readme: {
      content: marked(IndexListHeaderCellReadme),
    },
  }
)

indexListStories.add(
  'IndexListBody',
  () =&gt; {
    const indexListBodyRef = createRef()

    const logRef = (): void =&gt; {
      /* eslint-disable */
      console.log(indexListBodyRef.current)
      /* eslint-enable */
    }

    return (
github apache / incubator-echarts-doc / tool / md2json.js View on Github external
function mdToJsonSchema(mdStr, maxDepth, imagePath) {

    var renderer = new marked.Renderer();
    renderer.link = function (href, title, text) {
        if (href.match(/^~/)) { // Property link
            return '<a href="#' + href.slice(1) + '">' + text + '</a>';
        }
        else {
            // All other links are opened in new page
            return '<a href="' + href + '">' + text + '</a>';
        }
    };

    renderer.image = function (href, title, text) {
        var size = (text || '').split('x');
        if (isNaN(size[0])) {
            size[0] = 'auto';
        }
        if (isNaN(size[1])) {
github DanWebb / jdown / example / index.js View on Github external
const jdown = require('../dist');
const marked = require('marked');

// See https://marked.js.org/#/USING_PRO.md#renderer
const renderer = new marked.Renderer();
renderer.heading = (text, level) =&gt;
  `${text}`;

jdown('example/content', {
  fileInfo: true,
  markdown: {renderer},
  assets: {output: 'example/public', path: '/'}
}).then(content =&gt; console.log(content));
github CharlBest / nean-stack-starter / src / client / app / shared / github / github / github.component.ts View on Github external
async getMarkdownPage() {
    try {
      const response = await this.gitHubService.getFile(this.filePath);
      this.readmeText = parse(response);
      this.doneLoading.emit();
    } catch (error) {
      // TODO: error handling
    }
  }
}
github mathigon / textbooks / translations / encode.js View on Github external
function parseContent(content) {
  // Block Indentation
  content = content.split('\n').map((line) =&gt; {
    if (!line.startsWith(':::')) return line;
    return '\n\n' + encode(line) + '\n\n'
  }).join('\n');

  // Parse Markdown (but override HTML detection)
  const lexer = new marked.Lexer();
  lexer.rules.html = /^&lt;.*[\n]{2,}/;
  const tokens = lexer.lex(content);
  let parsed = marked.Parser.parse(tokens, {renderer});

  // Parse custom element attributes
  parsed = parsed.replace(/{([^}]+)}/g, (selection, body) =&gt; {
    return body.match(/^[0-9]+$/) ? selection : encode(selection)
  });

  parsed = parsed.replace(/&nbsp;/g, ' ');

  // Split into sections of length at most 1000.
  const output = [''];
  for (const row of parsed.split(/\n\n/)) {
    if (output[output.length - 1].length + row.length &lt; 4950) {
      output[output.length - 1] += '\n\n' + row
github linuxdeepin / deepin-manual / web / src / app / services / manual-renderer.ts View on Github external
const processMarkdown = function(src) {
  // Lex
  const lexer = new marked.Lexer();
  let tokens;
  try {
    tokens = lexer.lex(src);
  } catch (err) {
    throw new Error(`Lexer Error ${err}`);
  }

  // Extract Headers
  const parsed = parseNavigationItems(tokens);
  console.log('parsed: ', parsed);

  // Pass tokens to HTML renderer
  const html = marked(src, {
    renderer: getHTMLRenderer(),
  });
github dremio / dremio-oss / dac / ui / src / components / MarkdownEditor-spec.js View on Github external
describe('marked', () =&gt; {
    const marked = require('marked');

    const getCleanMarkup = markeup =&gt; marked(markeup).replace(/\r\n|\r|\n/g, ''); // remove new lines charactes

    const originalOptions = { ...marked.defaults };
    afterEach(() =&gt; {
      marked.setOptions(originalOptions);
    });

    // This functionality was broken by initial version of markedjsOverrides.js. So put tests here
    // to avoid this in future.
    it('Table is rendered', () =&gt; {
      const inputString = `| a | b | c | d | e |
      |---|---|---|---|---|
      | 1 | 2 | 3 | 4 | 5 |`;
      const html = '<table><thead><tr><th>a</th><th>b</th><th>c</th><th>d</th><th>e</th></tr></thead><tbody><tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr></tbody></table>';
      expect(getCleanMarkup(inputString)).to.be.equal(html);
    });

    const listOptionTests = isSmartLists =&gt; {
      // This functionality was broken by initial version of markedjsOverrides.js. So put tests here
github partageit / vegetables / lib / compile.js View on Github external
var updatedTokens = [];
	//console.log('file:', file.filename, 'tags:', commonTags);
	for (i = 0; i &lt; tokens.length; i++) {
		if ((i !== 0) &amp;&amp; (tokens[i].type === 'heading')) {
			if (tokens[i].depth &lt;= 2) {
				updatedTokens.push({'type': 'paragraph', 'text': '#HSLIDE'});
			} else if (tokens[i].depth &lt;= (commonTags.slideshow.headingLevel ? commonTags.slideshow.headingLevel : 3)) {
				updatedTokens.push({'type': 'paragraph', 'text': '#VSLIDE'});
			}
		}
		updatedTokens.push(tokens[i]);
	}
	updatedTokens.links = tokens.links;
	//console.log(updatedTokens);
	var renderer = mdRenderer(new marked.Renderer());
	var parser = new marked.Parser({renderer: renderer});
	var slideMarkdown = parser.parse(updatedTokens);

	// HTML content *************************************************************
	var content = marked.parser(tokens);

	// Autoreload tag ***********************************************************
	var autoReload = '';
	if ((config.mode === 'serve') &amp;&amp; config.serveAutoReload) {
		autoReload = '' +
		'';
	}

	// Add content to index *****************************************************
github tylercrosse / gitter-clone / src / server / controllers / messages.js View on Github external
export const addMessage = (io, action) => {
  const rawMarkup = marked(action.text);
  const doc = {
    username: action.username,
    text: action.text,
    rawMarkup,
    convo: action.convo
  };

  Convo.findOne({name: action.convo})
    .then(/* istanbul ignore next */(convo) => (_createMessage(doc, convo)))
    .then(_saveConvo)
    .then(/* istanbul ignore next */(result) => (_emitAddMessage(io, result)))
    .catch(/* istanbul ignore next */(err) => {
      logger.log('error', err);
    });
};
github dittos / diffmonster / src / ui / CommentThread.tsx View on Github external
function renderMarkdown(body: string): string {
  const rendered = marked(body, { gfm: true, sanitize: true });
  return rendered.replace(/&lt;(\/?sub)&gt;/g, '&lt;$1&gt;'); // TODO: is it okay?
}