开源软件名称(OpenSource Name):hexojs/hexo-renderer-markdown-it开源软件地址(OpenSource Url):https://github.com/hexojs/hexo-renderer-markdown-it开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):hexo-renderer-markdown-itThis renderer plugin uses Markdown-it as a render engine on Hexo. Adds support for Markdown and CommonMark. Main Features
InstallationWarning: make sure you're inside the main hexo directory before starting this guide. A default Hexo installation will include a markdown renderer plugin which uses $ npm un hexo-renderer-marked --save If you have already removed the default renderer, and others you might of added, you can now safely install $ npm i hexo-renderer-markdown-it --save Optionsmarkdown:
preset: 'default'
render:
html: true
xhtmlOut: false
langPrefix: 'language-'
breaks: true
linkify: true
typographer: true
quotes: '“”‘’'
enable_rules:
disable_rules:
plugins:
anchors:
level: 2
collisionSuffix: ''
permalink: false
permalinkClass: 'header-anchor'
permalinkSide: 'left'
permalinkSymbol: '¶'
case: 0
separator: '-' See below for more details. Advanced ConfigurationPreset optionsmarkdown:
preset: 'default'
Note that the default render and anchor options override some options in the preset. If you prefer to have the preset only: markdown:
preset: 'default'
render:
anchors: Render optionshtmlThe html: true # Doesn't escape HTML content
## OR
html: false # Escapes HTML content so the tags will appear as text. xhtmlOutThe xhtmlOut: true # Parser produces fully XHTML compliant code.
# Ex: A line breaks will be <br />
## OR
xhtmlOut: false # Parser will not produce XHTML compliant code.
# Ex: A line break will be <br> breaksMakes line breaks in the source file will be parsed into breaks: true # Parser produces `<br>` tags every time there is a line break in the source document.
## OR
breaks: false # Parser will ignore line breaks in the source document.
#Default double line break creates paragraph is still supported langPrefixAdd a prefix to the class name of code blocks (when a language is specified). langPrefix: 'language-' # default This option only applies when both Hexo's built-in highlighters are disabled. Example: langPrefix: 'lang-' Source:
HTML: <pre>
<code class="lang-js">example</code>
</pre> linkifyThe parser has the ability to inline links pasted directly into the text. If you write a piece of text that looks like a link it will be rendered as linkify: true # Returns text links as proper links inlined with the paragraph.
## OR
linkify: false # Returns text links as text. typographerThis is enables the substitution for common typography elements like ©, curly quotes, dashes, etc. typographer: true # Substitution of common typographical elements will take place.
## OR
typographer: false # No substitution, so dumb quotes will remain dumb quotes, etc. quotesDefines the double and single quotes used for substituting dumb quotes if typographer is set to quotes: '“”‘’' # "double" will be turned into “single”
# 'single' will be turned into ‘single’
## OR
quotes: '«»“”' # "double" will be turned into «single»
# 'single' will be turned into “single” Example configurationmarkdown:
render:
html: true
xhtmlOut: false
breaks: false
linkify: true
typographer: true
quotes: '“”‘’' Manage rulesCertain rules are enabled or disabled depending on the preset. For example, "zero" preset disables all rules, to enable specific rules: markdown:
preset: 'zero'
# Single rule
enable_rules: 'link'
# Multiple rules
enable_rules:
- 'link'
- 'image' "default" preset enables all rules, to disable specific rules: markdown:
preset: 'default'
# Single rule
disable_rules: 'link'
# Multiple rules
disable_rules:
- 'link'
- 'image' Available rulesSince the rules are subject to change, it's better to check the Markdown-it's source code for up-to-date rules. Look for the Automatic Headline ID'sEnables you to automatically create ID's for the headings so you can link back to them. A valid html document cannot have two elements with duplicate id value, for example if Default options: markdown:
anchors:
# Minimum level for ID creation. (Ex. h2 to h6)
level: 2
# A suffix that is prepended to the number given if the ID is repeated.
collisionSuffix: ''
# If `true`, creates an anchor tag with a permalink besides the heading.
permalink: false
# Class used for the permalink anchor tag.
permalinkClass: header-anchor
# Set to 'right' to add permalink after heading
permalinkSide: 'left'
# The symbol used to make the permalink
permalinkSymbol: ¶
# Transform anchor to (1) lower case; (2) upper case
case: 0
# Replace space with a character
separator: '-' PluginsIncluded plugins:
Plugins are not enabled by default, to enable: markdown:
plugins:
- markdown-it-abbr
# installed external plugins also can be enabled
- markdown-it-table-of-contents Plugin optionmarkdown:
plugins:
- name: 'markdown-it-emoji'
options:
shortcuts:
laughing: ':D'
- name: 'other-plugin'
options: ... ExtensibilityThis plugin overrides some default behaviors of how markdown-it plugin renders the markdown into html, to integrate with the Hexo ecosystem. It is possible to override this plugin too, without resorting to forking the whole thing. For example, to enable unsafe links (which is disabled by default): hexo.extend.filter.register('markdown-it:renderer', function(md) {
const { config } = this; // Optional, parse user config from _config.yml
md.validateLink = function() { return true; };
});
// Specify custom function in plugin option
const { slugize } = require('hexo-util');
const opts = hexo.config.markdown.anchors;
const mdSlugize = (str) => {
return slugize(str, { transform: opts.case, ...opts });
};
hexo.extend.filter.register('markdown-it:renderer', function(md) {
md.use(require('markdown-it-table-of-contents'), {
includeLevel: [2,3,4],
slugify: mdSlugize
});
}); Save the file in "scripts/" folder and run Hexo as usual. Refer to markdown-it API documentation. Requests and bug reportsIf you have any feature requests or bugs to report, you're welcome to file an issue. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论