How to use the markdown-it.render function in markdown-it

To help you get started, we’ve selected a few markdown-it 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 aotuzuche / auto-ui / scripts / lib / markdown-loader.js View on Github external
// 只认```,其他忽略
          if (token.markup === '```') {
            if (token.info === 'js') {
              // 插入到import后,component前
              moduleJS.push(token.content)
            } else if (token.info === 'jsx') {
              // 插入render内
              jsx = token.content
            }
          }
          i++
          token = tokens[idx + i]
        }

        // 描述也执行md
        return formatOpening(jsx, md.render(m[1]), flag)
      }
      return formatClosing(flag)
    }
  })
github ming-cult / snake-design / webpack / addImportLoader.js View on Github external
if (token.markup === '```') {
            // 里面的内容都当代码文本输出
            codeText = token.content
          }
          i++
          token = tokens[idx + i]
        }
        // 描述也执行md
        return formatOpening(codeText, md.render(m[1]), flag)
      }
      return formatClosing(flag)
    }
  })

  // md 处理过后的字符串含有 class 和 style ,需要再次处理给到react
  const content = md
    .render(body)
    .replace(/<hr>/g, '<hr>')
    .replace(/<br>/g, '<br>')
    .replace(/class=/g, 'className=')
    .replace(/style="text-align:center"/g, 'style={{ textAlign: "center"}}')
    .replace(/style="text-align:left"/g, 'style={{ textAlign: "left"}}')
    .replace(/style="text-align:right"/g, 'style={{ textAlign: "right"}}')
  return formatModule(imports, moduleJS.join('\n'), content, state)
}
github aotuzuche / auto-ui / scripts / lib / markdown-loader.js View on Github external
jsx = token.content
            }
          }
          i++
          token = tokens[idx + i]
        }

        // 描述也执行md
        return formatOpening(jsx, md.render(m[1]), flag)
      }
      return formatClosing(flag)
    }
  })

  // md 处理过后的字符串含有 class 和 style ,需要再次处理给到react
  let content = md
    .render(body)
    .replace(/<hr>/g, '<hr>')
    .replace(/<br>/g, '<br>')
    .replace(/class=/g, 'className=')
    .replace(/\[x\]/g, '<input disabled="" checked="" type="checkbox">')
    .replace(/\[ \]/g, '<input disabled="" type="checkbox">')

  return formatModule(imports, moduleJS.join('\n'), content)
}
github ming-cult / snake-design / webpack / addImportLoader.js View on Github external
// 从 ::: 下一个token开始
        let token = tokens[idx + i]

        // 如果没有到结尾
        while (token.markup !== ':::') {
          // 只认```,其他忽略
          if (token.markup === '```') {
            // 里面的内容都当代码文本输出
            codeText = token.content
          }
          i++
          token = tokens[idx + i]
        }
        // 描述也执行md
        return formatOpening(codeText, md.render(m[1]), flag)
      }
      return formatClosing(flag)
    }
  })
github aotuzuche / auto-ui / scripts / lib / markdown-loader.js View on Github external
jsx = token.content
            }
          }
          i++
          token = tokens[idx + i]
        }

        // 描述也执行md
        return formatOpening(jsx, md.render(m[1]), flag)
      }
      return formatClosing(flag)
    }
  })

  // md 处理过后的字符串含有 class 和 style ,需要再次处理给到react
  let content = md
    .render(body)
    .replace(/<hr>/g, '<hr>')
    .replace(/<br>/g, '<br>')
    .replace(/class=/g, 'className=')
    .replace(/\[x\]/g, '<input disabled="" checked="" type="checkbox">')
    .replace(/\[ \]/g, '<input disabled="" type="checkbox">')

  return formatModule(imports, moduleJS.join('\n'), content)
}
github liyatang / markdown-it-react-loader / index.js View on Github external
// 只认```,其他忽略
          if (token.markup === '```') {
            if (token.info === 'js') {
              // 插入到import后,component前
              moduleJS.push(token.content)
            } else if (token.info === 'jsx') {
              // 插入render内
              jsx = token.content
            }
          }
          i++
          token = tokens[idx + i]
        }

        // 描述也执行md
        return formatOpening(jsx, md.render(m[1]), flag)
      }
      return formatClosing(flag)
    }
  })
github NervJS / taro-ui / build / addImportLoader.js View on Github external
// 从 ::: 下一个token开始
        let token = tokens[idx + i]

        // 如果没有到结尾
        while (token.markup !== ':::') {
          // 只认```,其他忽略
          if (token.markup === '```') {
            // 里面的内容都当代码文本输出
            codeText = token.content
          }
          i++
          token = tokens[idx + i]
        }
        // 描述也执行md
        return formatOpening(codeText, md.render(m[1]), flag)
      }
      return formatClosing(flag)
    }
  })
github Sebastian-Fitzner / mangony / test / fixtures / helpers / helper-markdown.js View on Github external
Handlebars.registerHelper('markdown', function(path) {
			var content = fs.readFileSync(path, 'utf-8');

			return new Handlebars.SafeString(md.render(content));
		});
	};
github gucong3000 / FELS / server.js View on Github external
require("fs").readFile(require.resolve("./markdown.html"), function(err, html) {
				let type;
				if (!err) {
					data = html.toString().replace(/(<title>)\s*(&lt;\/title&gt;)/i, `$1${ data.title }$2`).replace(/(&lt;div class="row"&gt;\n*)\s*(\n*&lt;\/div&gt;)/i, "$1" + require("markdown-it")().render("# " + data.title + "\n\n" + (desc ? "## " + desc + "\n\n" : "") + data.explanation) + "$2");
					type = "html";
				} else {
					type = "markdown";
				}
				res.type(type).send(data);
			});
		}</title>
github chiaweilee / umi-plugin-md / src / helpers / markdown.ts View on Github external
export default function(source: string, options = {} as object): string {
  return require('markdown-it')(
    'default',
    Object.assign(
      {
        html: true,
        xhtmlOut: true,
        breaks: true,
        linkify: true,
        typographer: true,
        highlight: renderHighlight,
      },
      options,
    ),
  ).render(source);
}