Skip to content

Instantly share code, notes, and snippets.

@motleydev
Created October 3, 2016 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motleydev/e35143949850526c9fa9c9da50f0f959 to your computer and use it in GitHub Desktop.
Save motleydev/e35143949850526c9fa9c9da50f0f959 to your computer and use it in GitHub Desktop.
'use strict';
/* eslint-env commonjs */
/* Dependencies */
var visit = require('unist-util-visit');
// var lowlight = require('lowlight');
/**
* Attacher.
*
* @param {Unified} origin - Origin processor.
* @param {Object} [options={}] - Configuration.
* @return {Function} - Transformer.
*/
function attacher(origin, options) {
var settings = options || {};
var detect = settings.subset !== false;
var prefix = settings.prefix;
var name = 'hljs';
var pos;
return function (tree) {
visit(tree, 'element', function (node, index, parent) {
var props = node.properties;
var result;
var lang;
if (['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].indexOf(node.tagName) == -1) {
return;
}
let target = node.children[0];
let {position, type, value} = target;
node.children = [];
delete target.value;
let words = value.split(" ");
words.forEach((word, index) => {
node.children.push({
type: 'element',
tagName: 'span',
children: [
{
type: "text",
value: word
}
]
// position: position
})
if (index < words.length - 1 ) {
node.children.push({
type: 'element',
tagName: 'span',
children: [
{
type: "text",
value: " "
}
]
// position: position
})
}
});
});
};
}
/* Expose. */
module.exports = attacher;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment