当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript marked.setOptions函数代码示例

本文整理汇总了TypeScript中marked.setOptions函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setOptions函数的具体用法?TypeScript setOptions怎么用?TypeScript setOptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setOptions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: convertJson

function convertJson(input: string, outputFile: string, keysFile?: string, yamlFile?: string): Promise<void> {
	const render = new Renderer();

	marked.setOptions({
		renderer: render
	});

	marked(input);

	const promises: Array<Promise<void>> = [ writeFilePromise(outputFile, render.getOutput()) ];

	if (keysFile) {
		let treeKeys: any = {};

		addChildKeys(render.getFullObject().children, treeKeys);

		let jsonStr = JSON.stringify(treeKeys, null, 4);

		promises.push(writeFilePromise(keysFile, jsonStr));
	}

	if (yamlFile) {
		promises.push(writeFilePromise(yamlFile, render.getYamlOutput()));
	}

	return Promise.all(promises).then(() => undefined);
}
开发者ID:tristau,项目名称:dnd-5e-srd,代码行数:27,代码来源:index.ts

示例2: ngOnInit

  ngOnInit() {
    let markdownFile = this.block.source;
    this.markdown = require('raw-loader!../../../../assets/articles/' + markdownFile);
    let md = marked.setOptions({
      highlight: (code) => Prism.highlight(code.trim(), Prism.languages.jsx)
    });

    this.markdown = md.parse(this.markdown.trim());
  }
开发者ID:AhmedFawzy,项目名称:react-native-ui-kitten,代码行数:9,代码来源:react-markdown-block.component.ts

示例3: constructor

  constructor() {
    marked.setOptions({
      langPrefix: 'hljs ',
      highlight: function (code: string, lang: string) {
        return hljs.highlight(lang, code).value;
      }
    });

    fs.watchFile(entriesFilename, () => this.loadBlogEntries());
    this.loadBlogEntries(); 
  }
开发者ID:eliakaris,项目名称:blog,代码行数:11,代码来源:BlogProvider.ts

示例4: transform

	transform(value: string, args: string[]) : any {
		marked.setOptions({
			renderer: new marked.Renderer(),
			gfm: true,
			tables: true,
			breaks: false,
			pedantic: false,
			sanitize: true,
			smartLists: true,
			smartypants: false
		});
		var result = marked(value);
				return result;
		}
开发者ID:Bitfroest,项目名称:CopterLeague,代码行数:14,代码来源:markdown.pipe.ts

示例5: convertToMarkdown

export function convertToMarkdown(data) {
  marked.setOptions({
    renderer: new marked.Renderer(),
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: false,
    sanitize: true,
    smartLists: true,
    smartypants: false
  });

  return marked(data);
}
开发者ID:343829084,项目名称:growth2,代码行数:14,代码来源:helper.ts

示例6: constructor

    constructor(private sanitizer: DomSanitizationService) {
        this.md = marked;
        const renderer = new this.md.Renderer();
        renderer.code = (code, language) => {
            // Check whether the given language is valid for highlight.js.
            const validLang = !!(language && highlight.getLanguage(language));
            // Highlight only if the language is valid.
            const highlighted = validLang ? highlight.highlight(language, code).value : code;
            // Render the highlighted code with `hljs` class.
            return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
        };

        // Set the renderer to marked.
        marked.setOptions({ renderer });
    }
开发者ID:seattlecodercamps,项目名称:Blixen,代码行数:15,代码来源:markdown.component.ts

示例7: renderMarkdownToHtml

function renderMarkdownToHtml(markdown: string) {
  marked.setOptions({
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: false,
    sanitize: false,
    smartLists: true,
    smartypants: false,
    renderer: new marked.Renderer(),
    highlight: (code, lang) => {
      return highlightAuto(code, lang ? [lang] : undefined).value;
    }
  });

  return marked(markdown);
}
开发者ID:kevinphelps,项目名称:kevinphelps.me,代码行数:17,代码来源:markdown.pipe.ts

示例8: formatMarkdownValue

export function formatMarkdownValue(value, format) {
  if (format === "html" || format === "markdown") {
    const renderer = new marked.Renderer()
    marked.setOptions({
      renderer,
      gfm: true,
      tables: true,
      breaks: true,
      pedantic: false,
      sanitize: false,
      smartypants: false,
    })
    return marked(value)
  }

  return value
}
开发者ID:xtina-starr,项目名称:metaphysics,代码行数:17,代码来源:markdown.ts

示例9: initializeMarked

 /**
  * Support GitHub flavored Markdown, leave sanitizing to external library.
  */
 function initializeMarked(): void {
   if (markedInitialized) {
     return;
   }
   markedInitialized = true;
   marked.setOptions({
     gfm: true,
     sanitize: false,
     tables: true,
     // breaks: true; We can't use GFM breaks as it causes problems with tables
     langPrefix: `cm-s-${CodeMirrorEditor.defaultConfig.theme} language-`,
     highlight: (code, lang, callback) => {
       let cb = (err: Error | null, code: string) => {
         if (callback) {
           callback(err, code);
         }
         return code;
       };
       if (!lang) {
         // no language, no highlight
         return cb(null, code);
       }
       Mode.ensure(lang)
         .then(spec => {
           let el = document.createElement('div');
           if (!spec) {
             console.log(`No CodeMirror mode: ${lang}`);
             return cb(null, code);
           }
           try {
             Mode.run(code, spec.mime, el);
             return cb(null, el.innerHTML);
           } catch (err) {
             console.log(`Failed to highlight ${lang} code`, err);
             return cb(err, code);
           }
         })
         .catch(err => {
           console.log(`No CodeMirror mode: ${lang}`);
           console.log(`Require CodeMirror mode error: ${err}`);
           return cb(null, code);
         });
       return code;
     }
   });
 }
开发者ID:jupyter,项目名称:jupyterlab,代码行数:49,代码来源:renderers.ts

示例10: formatPrInfo

    function formatPrInfo(pull, length) {
        const paddedLength = length - 5
        const title = wrap(paddedLength)(pull.title)

        const labels = pull.labels.length > 0 && pull.labels.map(label => label.name).join(', ')
        const singularOrPlural = labels && pull.labels.length > 1 ? 's' : ''
        const formattedLabels = labels
            ? logger.colors.yellow(`\nLabel${singularOrPlural}: ${labels}`)
            : ''

        let info = `${title}${formattedLabels}`

        if (showDetails) {
            marked.setOptions({
                renderer: new TerminalRenderer({
                    reflowText: true,
                    width: paddedLength,
                }),
            })

            info = `
                ${logger.colors.blue('Title:')}

                ${title}

                ${formattedLabels.split('\n')[1] || ''}

                ${logger.colors.blue('Body:')}

                ${marked(pull.body || 'N/A')}
            `
        }

        if (options.link || showDetails) {
            info = `
                ${info}
                ${logger.colors.cyan(pull.html_url)}
            `
        }

        return info
            .replace(/  +/gm, '')
            .replace(/(\n\n\n)/gm, '\n')
            .trim()
    }
开发者ID:node-gh,项目名称:gh,代码行数:45,代码来源:pull-request.ts

示例11: convertMarkedHtml

export function convertMarkedHtml(content: string): string {
  marked.setOptions({
    highlight: function (code: string, lang: string): string {
      if (lang === undefined) {
          return code
      }
      
      const langSplit = lang.split(':')
      try {
          return highlight(langSplit[0], code).value
      } catch (e) {
          console.log(e.message)
          return code
      }
    }
  })

  return marked(content)
}
开发者ID:civic,项目名称:markcat,代码行数:19,代码来源:marked.ts

示例12: catch

import marked from 'marked';
import hjs from 'highlightjs';

marked.setOptions({
  gfm:         true,
  tables:      true,
  breaks:      false,
  sanitize:    false,
  smartypants: false,
  pedantic:    false,
  highlight: (code, lang) => {
    let result: hjs.IHighlightResult|hjs.IAutoHighlightResult;
    // highlight.js throws an error when highlighting an unknown lang.
    if (lang) {
      try {
        result = hjs.highlight(lang, code);
      } catch (err) {
        result = hjs.highlightAuto(code);
      }
    } else {
      result = hjs.highlightAuto(code);
    }
    // Neuter interpolations. This is necessary to prevent atril from
    // evaluating them in code blocks.
    result.value = result.value.replace(/\{\{((?:[^}]|}(?=[^}]))*)\}\}/g, '{{<span>$1</span>}}');
    return result.value;
  }
});

/**
 * marked rendering enhancements.
开发者ID:Mitranim,项目名称:atril,代码行数:31,代码来源:config.ts

示例13: setOptions

 public static setOptions(options: MarkedOptions): void {
     marked.setOptions(options);
 }
开发者ID:rajkeshwar,项目名称:rajkeshwar-repo,代码行数:3,代码来源:common.pipes.ts

示例14: function

import { Directive, ElementRef, Input,HostListener  } from '@angular/core';
import marked from 'marked';
import highlight from 'highlight.js'


marked.setOptions({
  renderer: new marked.Renderer(),
  gfm: true,
  tables: true,
  breaks: false,
  pedantic: false,
  sanitize: false,
  smartLists: true,
  smartypants: false,
  highlight: function (code) {
    return highlight.highlightAuto(code).value;
  }
});

@Directive({
  selector: '[withMarkdown]'
})
export class MarkdownDirective {

  @Input('withMarkdown') content:string;

  constructor(
    private el: ElementRef
  ) {
    this.el.nativeElement.classList.add('article-viewer')
  }
开发者ID:ZhaoUjun,项目名称:bolg-v1,代码行数:31,代码来源:markdown.directive.ts

示例15: highlightFn

const options = {
    gfm: true,
    tables: true,
    breaks: false,
    pedantic: true,
    sanitize: false,
    smartLists: true,
    smartypants: false,
    langPrefix: 'lang-',
    renderer: new marked.Renderer()
};

options.renderer.code = function highlightFn(code, language) {
    const validLang = !!(language && hljs.getLanguage(language));
    const highlighted = validLang ? hljs.highlight(language, code).value : code;
    return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
};

marked.setOptions(options);

@Injectable()
export class MarkdownService {
    constructor(private _domSanitizer: DomSanitizer) {}
    render(input: string) {
        if (!input) return;
        return this._domSanitizer.bypassSecurityTrustHtml(marked(input));
    }
}

开发者ID:csgpro,项目名称:csgpro.com,代码行数:28,代码来源:markdown.service.ts


注:本文中的marked.setOptions函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。