diff --git a/lib/search.js b/lib/search.js
index 17c1b7b..1acd84f 100644
--- a/lib/search.js
+++ b/lib/search.js
@@ -6,6 +6,8 @@ var toString = require('mdast-util-to-string')
var visit = require('unist-util-visit')
var is = require('unist-util-is')
var slugs = require('github-slugger')()
+var hastToString = require('hast-util-to-string')
+var rehype = require('rehype')
var HEADING = 'heading'
@@ -43,6 +45,11 @@ function search(root, expression, settings) {
return {index: headingIndex, endIndex: closingIndex, map: map}
function onheading(child, index, parent) {
+ visit(child, 'html', function(node) {
+ node.type = 'text'
+ node.value = hastToString(rehype.parse(node.value))
+ })
+
var value = toString(child)
var id = child.data && child.data.hProperties && child.data.hProperties.id
diff --git a/package.json b/package.json
index 6494b01..11d9957 100644
--- a/package.json
+++ b/package.json
@@ -21,7 +21,9 @@
],
"dependencies": {
"github-slugger": "^1.2.1",
+ "hast-util-to-string": "^1.0.1",
"mdast-util-to-string": "^1.0.5",
+ "rehype": "^7.0.0",
"unist-util-is": "^2.1.2",
"unist-util-visit": "^1.1.0"
},
diff --git a/test/index.js b/test/index.js
index 56c794b..5e39b39 100644
--- a/test/index.js
+++ b/test/index.js
@@ -115,3 +115,67 @@ test('processing nodes', function(t) {
t.end()
})
+
+test('processing html node', function(t) {
+ var htmlNode = u('root', [
+ u('heading', {depth: 1}, [
+ u('text', {value: 'Hello '}),
+ u('html', {value: 'World
'})
+ ])
+ ])
+
+ var htmlNestedNode = u('root', [
+ u('heading', {depth: 1}, [
+ u('text', {value: 'Hello '}),
+ u('paragraph', [u('html', {value: '