diff --git a/packages/core/spec/share/asciidoctor-spec.cjs b/packages/core/spec/share/asciidoctor-spec.cjs index 429c6f65b..59962db56 100644 --- a/packages/core/spec/share/asciidoctor-spec.cjs +++ b/packages/core/spec/share/asciidoctor-spec.cjs @@ -2059,6 +2059,36 @@ America/New_York expect(html).to.include('
Europe/London\nAmerica/New_York
') expect(html).to.include('') }) + + 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 `${source}${lang}` + } + } + + 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('
puts \'Hello, World!\'
') + expect(html).to.include('
Europe/London\nAmerica/New_York
') + expect(html).to.include('') + }) }) describe('Table', function () { diff --git a/packages/core/src/asciidoctor-core-api.js b/packages/core/src/asciidoctor-core-api.js index 2dc6e5efd..e95e0df65 100644 --- a/packages/core/src/asciidoctor-core-api.js +++ b/packages/core/src/asciidoctor-core-api.js @@ -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 {