Default markdown formatter is now markdown-it. This gives access to extended functionality such as: table of contents generation, super text, section tags, definition lists, and much more.
							parent
							
								
									e1b8f765de
								
							
						
					
					
						commit
						89fd896337
					
				
							
								
								
									
										38
									
								
								index.js
								
								
								
								
							
							
						
						
									
										38
									
								
								index.js
								
								
								
								
							| 
						 | 
				
			
			@ -327,34 +327,18 @@ qwiki.addMIMEtype('png', 'image/png');
 | 
			
		|||
qwiki.addMIMEtype('svg', 'image/svg+xml');
 | 
			
		||||
qwiki.addMIMEtype('css', 'text/css');
 | 
			
		||||
 | 
			
		||||
var m_markdown = require("markdown").markdown;
 | 
			
		||||
qwiki.addFormat('md', 'Markdown', function(source) {
 | 
			
		||||
  // parse the markdown into a tree and grab the link references
 | 
			
		||||
  var tree = m_markdown.parse( source.toString() );
 | 
			
		||||
  if (!tree[1] || !tree[1].references) {
 | 
			
		||||
    tree.splice(1, 0, { 'references' : {} });
 | 
			
		||||
  }
 | 
			
		||||
  var refs = tree[1].references;
 | 
			
		||||
  // iterate through the tree finding link references
 | 
			
		||||
  ( function find_link_refs( jsonml ) {
 | 
			
		||||
    if (jsonml[0] === "link_ref") {
 | 
			
		||||
      var ref = jsonml[1].ref;
 | 
			
		||||
      if (!refs[ref]) {
 | 
			
		||||
        refs[ref] = {
 | 
			
		||||
          href: ref.replace(/\s+/, "_" )
 | 
			
		||||
        };
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      for (var item in jsonml) {
 | 
			
		||||
        if (Array.isArray(jsonml[item])) {
 | 
			
		||||
          find_link_refs(jsonml[item]);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  } )( tree );
 | 
			
		||||
  // convert the tree into html
 | 
			
		||||
  return m_markdown.renderJsonML(m_markdown.toHTMLTree(tree));
 | 
			
		||||
var m_markdownit = require('markdown-it')({
 | 
			
		||||
  typographer: true
 | 
			
		||||
});
 | 
			
		||||
m_markdownit.use(require('markdown-it-anchor'));
 | 
			
		||||
m_markdownit.use(require('markdown-it-table-of-contents'), {includeLevel: "2-8"});
 | 
			
		||||
m_markdownit.use(require('markdown-it-deflist'));
 | 
			
		||||
m_markdownit.use(require('markdown-it-header-sections'));
 | 
			
		||||
m_markdownit.use(require('markdown-it-sup'));
 | 
			
		||||
qwiki.addFormat('md', 'Markdown', function(source) {
 | 
			
		||||
  return m_markdownit.render(source);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
qwiki.setDefault('format', 'md');
 | 
			
		||||
 | 
			
		||||
// **** DEFAULT
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,11 @@
 | 
			
		|||
  "author": "kts of kettek <kettek1@kettek.net> (https://kettek.net/)",
 | 
			
		||||
  "license": "GPLv3",
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "markdown": "^0.5.0"
 | 
			
		||||
    "markdown-it": "^5.0.2",
 | 
			
		||||
    "markdown-it-anchor": "^2.3.2",
 | 
			
		||||
    "markdown-it-deflist": "^2.0.0",
 | 
			
		||||
    "markdown-it-header-sections": "^0.2.0",
 | 
			
		||||
    "markdown-it-sup": "^1.0.0",
 | 
			
		||||
    "markdown-it-table-of-contents": "^0.1.2"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -322,3 +322,42 @@ textarea:focus,input:focus {
 | 
			
		|||
#content ul {
 | 
			
		||||
  margin-left: 1em;
 | 
			
		||||
}
 | 
			
		||||
/* content definition list styling */
 | 
			
		||||
dl {
 | 
			
		||||
}
 | 
			
		||||
dt {
 | 
			
		||||
  font-weight: bold;
 | 
			
		||||
  color: #3c3c57;
 | 
			
		||||
  padding-left: 1em;
 | 
			
		||||
}
 | 
			
		||||
dd {
 | 
			
		||||
  text-align: left;
 | 
			
		||||
}
 | 
			
		||||
/* content table styling */
 | 
			
		||||
table {
 | 
			
		||||
  box-shadow: rgba(0,0,0, 0.2) 0px 0px 4px; 
 | 
			
		||||
  -moz-box-shadow: rgba(0,0,0, 0.2) 0px 0px 4px; 
 | 
			
		||||
  -webkit-box-shadow: rgba(0,0,0, 0.2) 0px 0px 4px; 
 | 
			
		||||
}
 | 
			
		||||
thead {
 | 
			
		||||
  background-color: #3c3c57;
 | 
			
		||||
  color: #ececf7;
 | 
			
		||||
}
 | 
			
		||||
tr {
 | 
			
		||||
}
 | 
			
		||||
th {
 | 
			
		||||
  padding: 0.5em;
 | 
			
		||||
}
 | 
			
		||||
tbody {
 | 
			
		||||
}
 | 
			
		||||
td {
 | 
			
		||||
  padding: 0.5em;
 | 
			
		||||
  background-color: #fcfce2;
 | 
			
		||||
  box-shadow: rgba(0,0,0, 0.2) 0px 0px 4px; 
 | 
			
		||||
  -moz-box-shadow: rgba(0,0,0, 0.2) 0px 0px 4px; 
 | 
			
		||||
  -webkit-box-shadow: rgba(0,0,0, 0.2) 0px 0px 4px; 
 | 
			
		||||
}
 | 
			
		||||
/* section */
 | 
			
		||||
section {
 | 
			
		||||
  padding-left: 0.5em;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue