Skip to content

Dead code in api/src/graphgists/utils.js #48

Open
@ggrossetie

Description

@ggrossetie

The condition if (rawHtml === "") is always false since we prepend HTML to the variable rawHtml:

let rawHtml = asciidoctor.convert(asciidoc, { attributes });
rawHtml = `${rawHtml}<span id="metadata" author="${attributes['author'] || ''}" version="${attributes['neo4j-version'] || ''}" twitter="${attributes['twitter'] || ''}" tags="${attributes['tags'] || ''}" />`;
if (rawHtml === "") {
throw new ValidationError(
[{ key: "asciidoc", message: "AsciiDoc is empty, it is required." }],
"AsciiDoc is empty, it is required."
);
}

As a result, the ValidationError will never be thrown.

Furthermore, it would be better to use an Asciidoctor Postprocessor extension to prepend content: https://docs.asciidoctor.org/asciidoctor/latest/extensions/postprocessor/

Here's an example (untested code):

metadata-postprocessor.js

module.exports = function (registry) {
  registry.postprocessor(function () {
    var self = this
    self.process(function (doc, output) {
      const attributes = doc.getAttributes()
      return `${output}<span id="metadata" author="${attributes['author'] || ''}" version="${attributes['neo4j-version'] || ''}" twitter="${attributes['twitter'] || ''}" tags="${attributes['tags'] || ''}" />`
    })
  })
}

And then you can register this extension:

const asciidoctor = require('asciidoctor')()
const registry = asciidoctor.Extensions.create()

// register the extension
const metadataPostProcessorExtension = require('./metadata-postprocessor.js')
metadataPostProcessorExtension(registry)

// convert text using the extension registry
asciidoctor.convert('text', { 'extension_registry': registry })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions