Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ggrossetie opened this issue Aug 9, 2021 · 0 comments
Open

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

ggrossetie opened this issue Aug 9, 2021 · 0 comments

Comments

@ggrossetie
Copy link
Collaborator

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 })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant