bobheadxi / readable

👓 Opinionated Markdown formatter, featuring semantic line breaks
https://bobheadxi.dev/semantic-line-breaks/
20 stars 4 forks source link

Readable throws an error when it encounters multi line link element #18

Closed m-spitfire closed 1 year ago

m-spitfire commented 1 year ago

File to reproduce (minimal.md):

We want to convert this into an error. In some cases, there may be an
existing error for this scenario. In others, we will need to allocate a
fresh diagnostic code.  [Instructions for allocating a fresh diagnostic
code can be found here.](./diagnostics/diagnostic-codes.md) You may want
to mention in the extended description that the compiler behavior
changed on this point, and include a reference to the tracking issue for
the change.

Running

readable check minimal.md

On master and v2.2 it throws error:

ERROR failed to render '/home/muradb/personal/rustc-dev-guide/minimal.md', aborting: Error: Cannot take length of multi-line node '[object Object]'
Toggle full backtrace of error ``` Error: Cannot take length of multi-line node '[object Object]' at nodeLength (file:///home/muradb/personal/readable/markdown/ast.ts:92:16) at ReflowParagraphState.addRawNode (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:84:31) at processParent (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:288:41) at reflowParagraph (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:321:3) at visit (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:335:9) at file:///home/muradb/personal/readable/plugins/readable/reflow.ts:338:42 at Array.forEach () at visit (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:338:23) at transformer (file:///home/muradb/personal/readable/plugins/readable/reflow.ts:344:5) at wrapped (https://jspm.dev/npm:trough@1.0.5!cjs:21:19) ```

Upon further having some console.log s in nodeLength function, it's clear that the error occurs because of link element in the example, specifically when it tries to check for if node is literal: https://github.com/bobheadxi/readable/blob/8e53ead732ac73e4d6e0d29ebca407083525b0be/markdown/ast.ts#L90 which link element is not, so it just throws error. I am not sure about the whole codebase, but if you tell me what's it supposed to do when it encounters a link element, I can send a pull request.

bobheadxi commented 1 year ago

Thanks for reporting this - https://github.com/bobheadxi/readable/pull/19 should fix it :)

m-spitfire commented 1 year ago

Thanks for the fix!