Skip to content

Support multi-line tips and warns #690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"postinstall": "opencollective postinstall"
},
"dependencies": {
"he": "^1.2.0",
"marked": "^0.5.1",
"medium-zoom": "^0.4.0",
"opencollective": "^1.0.3",
Expand Down
4 changes: 2 additions & 2 deletions src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ export class Compiler {
origin.paragraph = renderer.paragraph = function (text) {
let result
if (/^!>/.test(text)) {
result = helperTpl('tip', text)
result = helperTpl('tip', text, /!>/)
} else if (/^\?>/.test(text)) {
result = helperTpl('warn', text)
result = helperTpl('warn', text, /\?>/)
} else {
result = `<p>${text}</p>`
}
Expand Down
10 changes: 8 additions & 2 deletions src/core/render/tpl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {isMobile} from '../util/env'
import marked from 'marked'
import he from 'he'

/**
* Render github corner
* @param {Object} data
Expand Down Expand Up @@ -92,8 +95,11 @@ export function tree(toc, tpl = '<ul class="app-sub-sidebar">{inner}</ul>') {
return tpl.replace('{inner}', innerHTML)
}

export function helper(className, content) {
return `<p class="${className}">${content.slice(5).trim()}</p>`
export function helper(className, content, headingRegexp) {
const regexp = new RegExp('(^|\n)' + headingRegexp.source + ' ?', 'g')
const raw = he.decode(content).replace(regexp, '$1')
const html = marked(raw);
return `<div class="${className}">${html}</div>`
}

export function theme(color) {
Expand Down
16 changes: 14 additions & 2 deletions src/themes/basic/_layout.styl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ body.sticky
&:nth-child(2n)
background-color #f8f8f8

.markdown-section p.tip
.markdown-section div.tip
background-color #f8f8f8
border-bottom-right-radius 2px
border-left 4px solid #f66
Expand All @@ -372,17 +372,29 @@ body.sticky
text-align center
top 14px

&>:first-child
margin-top: 0;

&>:last-child
margin-bottom: 0;

code
background-color #efefef

em
color $color-text

.markdown-section p.warn
.markdown-section div.warn
background rgba($color-primary, 0.1)
border-radius 2px
padding 1rem

&>:first-child
margin-top: 0;

&>:last-child
margin-bottom: 0;

body.close
.sidebar
transform translateX(- $sidebar-width)
Expand Down
2 changes: 1 addition & 1 deletion src/themes/dark.styl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pre::after
text-align right
top 0

.markdown-section p.tip
.markdown-section div.tip
background-color #282828
color #657b83

Expand Down