@@ -19,23 +19,25 @@ const SocketPlugins = require.main.require('./src/socket.io/plugins');
1919SocketPlugins . markdown = require ( './websockets' ) ;
2020
2121let parser ;
22-
22+ let app ;
2323const Markdown = {
2424 config : { } ,
2525 _externalImageCache : undefined ,
2626 _externalImageFailures : new Set ( ) ,
2727 onLoad : async function ( params ) {
28+ app = params . app ;
29+ const { router } = params ;
2830 const controllers = require ( './lib/controllers' ) ;
2931 const hostMiddleware = require . main . require ( './src/middleware' ) ;
32+ const routeHelpers = require . main . require ( './src/routes/helpers' ) ;
3033 const middlewares = [
3134 hostMiddleware . maintenanceMode , hostMiddleware . registrationComplete , hostMiddleware . pluginHooks ,
3235 ] ;
3336
34- params . router . get ( '/admin/plugins/markdown' , params . middleware . admin . buildHeader , controllers . renderAdmin ) ;
35- params . router . get ( '/api/admin/plugins/markdown' , controllers . renderAdmin ) ;
37+ routeHelpers . setupAdminPageRoute ( router , '/admin/plugins/markdown' , controllers . renderAdmin ) ;
3638
3739 // Return raw markdown via GET
38- params . router . get ( '/api/post/:pid/raw' , middlewares , controllers . retrieveRaw ) ;
40+ router . get ( '/api/post/:pid/raw' , middlewares , controllers . retrieveRaw ) ;
3941
4042 Markdown . init ( ) ;
4143 await Markdown . loadThemes ( ) ;
@@ -44,11 +46,18 @@ const Markdown = {
4446 } ,
4547
4648 getConfig : async ( config ) => {
47- const { defaultHighlightLanguage, highlightTheme } = await meta . settings . get ( 'markdown' ) ;
49+ let { defaultHighlightLanguage, highlightTheme, hljsLanguages, highlightLinesLanguageList } = await meta . settings . get ( 'markdown' ) ;
50+
51+ try {
52+ hljsLanguages = JSON . parse ( hljsLanguages ) ;
53+ } catch ( e ) {
54+ hljsLanguages = [ 'common' ] ;
55+ }
4856
4957 config . markdown = {
5058 highlight : Markdown . highlight ? 1 : 0 ,
51- highlightLinesLanguageList : Markdown . config . highlightLinesLanguageList ,
59+ highlightLinesLanguageList,
60+ hljsLanguages,
5261 theme : highlightTheme || 'default.css' ,
5362 defaultHighlightLanguage : defaultHighlightLanguage || '' ,
5463 } ;
@@ -79,7 +88,6 @@ const Markdown = {
7988
8089 langPrefix : 'language-' ,
8190 highlight : true ,
82- highlightLinesLanguageList : [ ] ,
8391 highlightTheme : 'default.css' ,
8492
8593 probe : true ,
@@ -95,7 +103,7 @@ const Markdown = {
95103 checkboxes : true ,
96104 multimdTables : true ,
97105 } ;
98- const notCheckboxes = [ 'langPrefix' , 'highlightTheme' , 'highlightLinesLanguageList' , ' probeCacheSize'] ;
106+ const notCheckboxes = [ 'langPrefix' , 'highlightTheme' , 'probeCacheSize' ] ;
99107
100108 meta . settings . get ( 'markdown' , ( err , options ) => {
101109 if ( err ) {
@@ -116,17 +124,6 @@ const Markdown = {
116124 _self . highlight = _self . config . highlight ;
117125 delete _self . config . highlight ;
118126
119- if ( typeof _self . config . highlightLinesLanguageList === 'string' ) {
120- try {
121- _self . config . highlightLinesLanguageList = JSON . parse ( _self . config . highlightLinesLanguageList ) ;
122- } catch ( e ) {
123- winston . warn ( '[plugins/markdown] Invalid config for highlightLinesLanguageList, blanking.' ) ;
124- _self . config . highlightLinesLanguageList = [ ] ;
125- }
126-
127- _self . config . highlightLinesLanguageList = _self . config . highlightLinesLanguageList . join ( ',' ) . split ( ',' ) ;
128- }
129-
130127 parser = new MarkdownIt ( _self . config ) ;
131128
132129 Markdown . updateParserRules ( parser ) ;
@@ -273,7 +270,8 @@ const Markdown = {
273270 renderHelp : async function ( helpContent ) {
274271 const translated = await translator . translate ( '[[markdown:help_text]]' ) ;
275272 const parsed = await plugins . hooks . fire ( 'filter:parse.raw' , `## Markdown\n${ translated } ` ) ;
276- helpContent += parsed ;
273+ const html = await app . renderAsync ( 'modals/markdown-help' , { } ) ;
274+ helpContent += parsed + html ;
277275 return helpContent ;
278276 } ,
279277
@@ -361,7 +359,7 @@ const Markdown = {
361359 // Validate the url
362360 if ( ! Markdown . isUrlValid ( attributes . get ( 'src' ) ) ) { return '' ; }
363361
364- token . attrSet ( 'class' , `${ token . attrGet ( 'class' ) || '' } img-responsive img-markdown` ) ;
362+ token . attrSet ( 'class' , `${ token . attrGet ( 'class' ) || '' } img-fluid img-markdown` ) ;
365363
366364 // Append sizes to images
367365 if ( parsedSrc . pathname ) {
0 commit comments