File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -343,6 +343,58 @@ <h4 style="margin:0 0 4px;font-size:1em;">${b.title}</h4>
343343 ]
344344} ) ;
345345
346+ // Admonitions
347+ CMS . registerEditorComponent ( {
348+ id : "admonition" ,
349+ label : "Admonition" ,
350+ fields : [
351+ {
352+ name : "type" ,
353+ label : "Admonition Type" ,
354+ widget : "select" ,
355+ options : [
356+ { label : "Note" , value : "note" } ,
357+ { label : "Info" , value : "info" } ,
358+ { label : "Warning" , value : "warning" } ,
359+ { label : "Caution" , value : "caution" } ,
360+ { label : "Construction" , value : "construction" }
361+ ] ,
362+ default : "note"
363+ } ,
364+ {
365+ name : "body" ,
366+ label : "Content" ,
367+ widget : "text" ,
368+ default : ""
369+ }
370+ ] ,
371+ pattern : / ^ { { <\s * a d m o n i t i o n \s + t y p e = " ( .* ?) " \s * > } } ( [ \s \S ] * ?) { { <\s * \/ a d m o n i t i o n \s * > } } $ / ,
372+
373+ fromBlock : function ( match ) {
374+ return {
375+ type : match [ 1 ] ,
376+ body : match [ 2 ] . trim ( )
377+ } ;
378+ } ,
379+
380+ toBlock : function ( obj ) {
381+ return [
382+ `{{< admonition type="${ obj . type } " >}}` ,
383+ obj . body ,
384+ `{{< /admonition >}}`
385+ ] . join ( "\n" ) ;
386+ } ,
387+
388+ preview : function ( obj ) {
389+ const title = obj . type . charAt ( 0 ) . toUpperCase ( ) + obj . type . slice ( 1 ) ;
390+ return `
391+ <div class="admonition ${ obj . type } ">
392+ <strong>${ title } :</strong> ${ CMS . previewFieldFormatter ( obj . body ) }
393+ </div>
394+ ` ;
395+ }
396+ } ) ;
397+
346398 </ script >
347399 </ body >
348400</ html >
You can’t perform that action at this time.
0 commit comments