Skip to content

Commit

Permalink
feat(markdown-loader): addcard-warpper
Browse files Browse the repository at this point in the history
  • Loading branch information
BeADre committed Nov 18, 2020
1 parent 5086937 commit 38ec300
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/varlet-markdown-loader/markdownLoader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const markdown = require('markdown-it')
const hljs = require('highlight.js')
const cardWrapper = require('./src/card-wrapper.js')

function highlight(str, lang) {
if (lang && hljs.getLanguage(lang)) {
Expand All @@ -19,7 +20,7 @@ function markLoader(source) {
typographer: true,
highlight,
})
const html = md.render(source)
const html = cardWrapper(md.render(source))

return (
'<template>\n' +
Expand Down
16 changes: 16 additions & 0 deletions packages/varlet-markdown-loader/src/card-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = function cardWrapper(html) {
const group = html
.replace(/<h3/g, ':::<h3')
.replace(/<h2/g, ':::<h2')
.split(':::')

return group
.map((fragment) => {
if (fragment.indexOf('<h3') !== -1) {
return `<div class="card">${fragment}</div>`
}

return fragment
})
.join('')
}

0 comments on commit 38ec300

Please sign in to comment.