Merge pull request #1306 from hackmdio/feature/configurable-break-style

Configurable default break style
This commit is contained in:
Yukai Huang 2019-11-01 12:16:06 +08:00 committed by GitHub
commit aa5a50facf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 13 deletions

View File

@ -164,6 +164,7 @@ module.exports = {
allowGravatar: true,
allowPDFExport: true,
openID: false,
defaultUseHardbreak: true,
// linkifyHeaderStyle - How is a header text converted into a link id.
// Header Example: "3.1. Good Morning my Friend! - Do you have 5$?"
// * 'keep-case' is the legacy CodiMD value.

View File

@ -137,5 +137,6 @@ module.exports = {
allowGravatar: toBooleanConfig(process.env.CMD_ALLOW_GRAVATAR),
allowPDFExport: toBooleanConfig(process.env.CMD_ALLOW_PDF_EXPORT),
openID: toBooleanConfig(process.env.CMD_OPENID),
defaultUseHardbreak: toBooleanConfig(process.env.CMD_DEFAULT_USE_HARD_BREAK),
linkifyHeaderStyle: process.env.CMD_LINKIFY_HEADER_STYLE
}

View File

@ -100,6 +100,7 @@ statusRouter.get('/config', function (req, res) {
plantumlServer: config.plantuml.server,
DROPBOX_APP_KEY: config.dropbox.appKey,
allowedUploadMimeTypes: config.allowedUploadMimeTypes,
defaultUseHardbreak: config.defaultUseHardbreak,
linkifyHeaderStyle: config.linkifyHeaderStyle
}
res.set({

View File

@ -195,7 +195,7 @@ export function isValidURL (str) {
export function parseMeta (md, edit, view, toc, tocAffix) {
let lang = null
let dir = null
let breaks = true
let breaks = window.defaultUseHardbreak
if (md && md.meta) {
const meta = md.meta
lang = meta.lang
@ -225,10 +225,10 @@ export function parseMeta (md, edit, view, toc, tocAffix) {
tocAffix.removeAttr('dir')
}
// breaks
if (typeof breaks === 'boolean' && !breaks) {
md.options.breaks = false
if (typeof breaks === 'boolean') {
md.options.breaks = breaks
} else {
md.options.breaks = true
md.options.breaks = window.defaultUseHardbreak
}
}
@ -1030,7 +1030,7 @@ function highlightRender (code, lang) {
export const md = markdownit('default', {
html: true,
breaks: true,
breaks: window.defaultUseHardbreak,
langPrefix: '',
linkify: true,
typographer: true,

View File

@ -6,6 +6,8 @@ window.plantumlServer = '<%- plantumlServer %>'
window.allowedUploadMimeTypes = <%- JSON.stringify(allowedUploadMimeTypes) %>
window.defaultUseHardbreak = <%- defaultUseHardbreak %>
window.linkifyHeaderStyle = '<%- linkifyHeaderStyle %>'
window.DROPBOX_APP_KEY = '<%- DROPBOX_APP_KEY %>'

View File

@ -49,6 +49,15 @@ const deps = [{
}
}]
// options from yaml meta
const meta = JSON.parse($('#meta').text())
// breaks
if (typeof meta.breaks === 'boolean') {
md.options.breaks = meta.breaks
} else {
md.options.breaks = window.defaultUseHardbreak
}
const slideOptions = {
separator: '^(\r\n?|\n)---(\r\n?|\n)$',
verticalSeparator: '^(\r\n?|\n)----(\r\n?|\n)$'
@ -70,8 +79,6 @@ const defaultOptions = {
dependencies: deps
}
// options from yaml meta
const meta = JSON.parse($('#meta').text())
var options = meta.slideOptions || {}
if (Object.hasOwnProperty.call(options, 'spotlight')) {
@ -103,12 +110,6 @@ if (meta.dir && typeof meta.dir === 'string' && meta.dir === 'rtl') {
} else {
options.rtl = false
}
// breaks
if (typeof meta.breaks === 'boolean' && !meta.breaks) {
md.options.breaks = false
} else {
md.options.breaks = true
}
// options from URL query string
const queryOptions = Reveal.getQueryHash() || {}