Skip to content

Commit

Permalink
resolves asciidoctor#1220 super.format
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Jan 10, 2023
1 parent 42ad9be commit 4da2f88
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/core/spec/share/asciidoctor-spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,36 @@ America/New_York
expect(html).to.include('<pre>Europe/London\nAmerica/New_York</pre>')
expect(html).to.include('<style>pre.prism{background-color: lightgrey}</style>')
})

it('should call super.format', () => {
class BuildHighlighter {
format (node, lang, opts) {
opts = Object.assign({}, opts, {
transform: (x, code) => {
code['$[]=']('class', `language-${lang || 'none'} hljs`)
},
})
return this.super({ caller: 'format' }, node, lang, opts)
}

handlesHighlighting () { return true }

highlight (node, source, lang, opts) {
return `<span>${source}</span><span>${lang}</span>`
}
}

asciidoctor.SyntaxHighlighter.register('build', BuildHighlighter)
const source = `[source,ruby]
----
puts 'Hello, World!'
----`
const doc = asciidoctor.load(source, { attributes: { 'source-highlighter': 'build' } })
const html = doc.convert({ standalone: true })
expect(html).to.include('<pre lang="ruby" class="prism wrap"><code>puts \'Hello, World!\'</code></pre>')
expect(html).to.include('<pre>Europe/London\nAmerica/New_York</pre>')
expect(html).to.include('<style>pre.prism{background-color: lightgrey}</style>')
})
})

describe('Table', function () {
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/asciidoctor-core-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,17 @@ function initializeClass (superClass, className, functions, defaultFunctions, ar
}
Opal.def(scope, '$initialize', initialize)
Opal.def(scope, 'super', function (func) {
if (typeof func === 'object' && typeof func.caller === 'string') {
const caller = func.caller
const argumentsList = Array.from(arguments).slice(1)
for (let i = 0; i < argumentsList.length; i++) {
// convert all (Opal) Hash arguments to JSON.
if (typeof argumentsList[i] === 'object' && typeof argumentsList[i].constructor === 'function' && typeof argumentsList[i].constructor.name === 'Object') {
argumentsList[i] = toHash(argumentsList[i])
}
}
return Opal.send(this, Opal.find_super_dispatcher(this, caller, this[`$${caller}`]), argumentsList)
}
if (typeof func === 'function') {
Opal.send(this, Opal.find_super_dispatcher(this, func.name, func))
} else {
Expand Down

0 comments on commit 4da2f88

Please sign in to comment.