• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript marked.setOptions函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: constructor

 constructor() {
   this.md = marked.setOptions({});
 }
开发者ID:Hub-of-all-Things,项目名称:Rumpel,代码行数:3,代码来源:markdown-to-html.pipe.ts


示例17: constructor

 constructor(private _configuration:Configuration) {
   this.md = marked.setOptions({
   });
   this.cfg = _configuration;
 }
开发者ID:sebsofen,项目名称:wren-gui,代码行数:5,代码来源:markdown.service.ts


示例18: highlight

    sanitize: true,
    smartLists: true,
    silent: false,
    highlight(code: string, lang: string) {
        return '';
    },
    langPrefix: 'lang-',
    smartypants: false,
    renderer: new marked.Renderer()
};

function callback() {
    console.log('callback called');
}

const myOldMarked: typeof marked = marked.setOptions(options);

console.log(marked('i am using __markdown__.'));
console.log(marked('i am using __markdown__.', options));
console.log(marked('i am using __markdown__.', callback));
console.log(marked('i am using __markdown__.', options, callback));

console.log(marked.parse('i am using __markdown__.'));
console.log(marked.parse('i am using __markdown__.', options));
console.log(marked.parse('i am using __markdown__.', callback));
console.log(marked.parse('i am using __markdown__.', options, callback));

const text = 'something';
const tokens: marked.TokensList = marked.lexer(text, options);
console.log(marked.parser(tokens));
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:30,代码来源:marked-tests.ts


示例19: require

var marked = require('marked');
var marked_terminal = require('marked-terminal');
var chalk = require('chalk');


// Add spacing around heading.
var _heading = marked_terminal.prototype.heading;
marked_terminal.prototype.heading = function() {
    var res = _heading.apply(this, arguments);
    return "\n" + res + "\n";
};

marked.setOptions({
    renderer: new marked_terminal({
        codespan: chalk.cyan,
        width: 65,
        reflowText: true,
    })
});

function help(jssh: base.Probe) {
    //jssh.helpFile = __dirname + '/../../help/print.md';

    // TODO: Should this be some function from `jssh` -> `jssh.logPlain`.
    var logger = console.log.bind(console);

    function no_help() {
        logger('Help is not available for this function.');
    }

    function help(func) {
开发者ID:streamich,项目名称:jssh-api-jssh,代码行数:31,代码来源:help.ts


示例20: ngAfterViewInit

 ngAfterViewInit() {
   let md = marked.setOptions({});
   this.el.nativeElement.innerHTML = md.parse(this.el.nativeElement.innerHTML.trim());
 }
开发者ID:AhmedFawzy,项目名称:react-native-ui-kitten,代码行数:4,代码来源:react-description.directive.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript marked.Lexer类代码示例发布时间:2022-05-25
下一篇:
TypeScript marked.parser函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap