asciidoctor / atom-asciidoc-preview

⚛ AsciiDoc preview for the Atom editor.
https://atom.io/packages/asciidoc-preview
MIT License
141 stars 42 forks source link

Using undefined attributes in anchor id results in Uncaught Syntax Error #276

Closed tylerkelly13 closed 6 years ago

tylerkelly13 commented 6 years ago

Description

Atom error is: Uncaught Error: Syntax error, unrecognized expression: #anchor-id-string_{attribute} Caused by use of undefined attribute in an anchor id. If:

The error will be thrown and the user is unable to edit the heading. This also occurs when the attribute is defined elsewhere (such as a master document) but you are only previewing the current file.

Workaround: close the preview and retry editing the heading.

Screenshots

No screenshot. See attached Stacktrace

Syntax example

[id='anchor-id-string_{attribute}']
= Title of a file to be in a master file where the attribute is defined

Stacktrace

stacktrace.txt

mojavelinux commented 6 years ago

This is the problematic line:

if target = $('#' + blockId)[0]

I've run into this problem before when working with user-provided IDs. jQuery doesn't protect against an illegal ID selector. Therefore, it's necessary to use getElementById to be safe:

if target = window.document.getElementById(blockId)