mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
#884 Merging configuration updates to previous condifguration.
This commit is contained in:
parent
92ac7d7c24
commit
b9ad9ba674
@ -1,8 +1,29 @@
|
||||
let config = {
|
||||
securityLevel: 'strict'
|
||||
}
|
||||
|
||||
const setConf = function (cnf) {
|
||||
// Top level initially mermaid, gflow, sequenceDiagram and gantt
|
||||
const lvl1Keys = Object.keys(cnf)
|
||||
for (let i = 0; i < lvl1Keys.length; i++) {
|
||||
if (typeof cnf[lvl1Keys[i]] === 'object' && cnf[lvl1Keys[i]] != null) {
|
||||
const lvl2Keys = Object.keys(cnf[lvl1Keys[i]])
|
||||
|
||||
for (let j = 0; j < lvl2Keys.length; j++) {
|
||||
// logger.debug('Setting conf ', lvl1Keys[i], '-', lvl2Keys[j])
|
||||
if (typeof config[lvl1Keys[i]] === 'undefined') {
|
||||
config[lvl1Keys[i]] = {}
|
||||
}
|
||||
// logger.debug('Setting config: ' + lvl1Keys[i] + ' ' + lvl2Keys[j] + ' to ' + cnf[lvl1Keys[i]][lvl2Keys[j]])
|
||||
config[lvl1Keys[i]][lvl2Keys[j]] = cnf[lvl1Keys[i]][lvl2Keys[j]]
|
||||
}
|
||||
} else {
|
||||
config[lvl1Keys[i]] = cnf[lvl1Keys[i]]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const setConfig = conf => {
|
||||
config = conf
|
||||
setConf(conf)
|
||||
}
|
||||
export const getConfig = () => config
|
||||
|
@ -10,7 +10,7 @@
|
||||
import * as d3 from 'd3'
|
||||
import scope from 'scope-css'
|
||||
import pkg from '../package.json'
|
||||
import { setConfig } from './config'
|
||||
import { setConfig, getConfig } from './config'
|
||||
import { logger, setLogLevel } from './logger'
|
||||
import utils from './utils'
|
||||
import flowRenderer from './diagrams/flowchart/flowRenderer'
|
||||
@ -534,16 +534,19 @@ const setConf = function (cnf) {
|
||||
|
||||
function initialize (options) {
|
||||
logger.debug('Initializing mermaidAPI ', pkg.version)
|
||||
|
||||
// Update default config with options supplied at initialization
|
||||
if (typeof options === 'object') {
|
||||
setConf(options)
|
||||
}
|
||||
setConfig(config)
|
||||
setLogLevel(config.logLevel)
|
||||
}
|
||||
|
||||
function getConfig () {
|
||||
return config
|
||||
}
|
||||
// function getConfig () {
|
||||
// console.warn('get config')
|
||||
// return config
|
||||
// }
|
||||
|
||||
const mermaidAPI = {
|
||||
render,
|
||||
|
Loading…
x
Reference in New Issue
Block a user