Skip to content

Only a single hyperlink per paragraph appears to be detected #28

@nospam3089

Description

@nospam3089

This is similar to #12 and #27, but different enough to mandate its own ticket.

Consider the following script md2adf.js taking markdown on stdin and giving adf on stdout. I.e. one of the simplest possible uses of this library:

#!/usr/bin/nodejs

const fnTranslate    = require( process.env["NPM_CONFIG_PREFIX"] +
    '/lib/node_modules/md-to-adf' )

process.stdin.on("data", data => {
    console.log(JSON.stringify(fnTranslate(data.toString())))
})

When feeding it with input using the following script: (deemed more overviewable than any more verbose example I would be able to produce in pure javascript)

#!/bin/sh -eu

working_desc='Markdown with one hyperlink works as expected:'
working_md='Markdown may contain [hyper links](https://example.com/) '

broken_desc='As soon as one adds a second one it breaks though:'
broken_md="$( echo 'Markdown may contain [hyper links](https://example.com/) ' \
  'note that plural means more than merely one [link](https://example.org/)' )"

workaround_desc='Working around it?:'
workaround_md="$( printf '%s\\n\\n%s\\n' \
  'Adding hard paragraph breaks [hyper links](https://example.com/)' \
  'seems to be a work around [link](https://example.org/)' )"

for example in working broken workaround; do
  echo $( eval echo "\$${example}_desc" )
  echo "$( eval echo "\$${example}_md" )" | ./md2adf.js
  echo
done

Running the above gives the following output:

Markdown with one hyperlink works as expected:
{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Markdown may contain "},{"type":"text","text":"hyper links","marks":[{"type":"link","attrs":{"href":"https://example.com/"}}]}]}],"version":1}

As soon as one adds a second one it breaks though:
{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Markdown may contain [hyper links](https://example.com/) note that plural means more than merely one "},{"type":"text","text":"link","marks":[{"type":"link","attrs":{"href":"https://example.org/"}}]}]}],"version":1}

Working around it?:
{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Adding hard paragraph breaks "},{"type":"text","text":"hyper links","marks":[{"type":"link","attrs":{"href":"https://example.com/"}}]}]},{"type":"paragraph","content":[{"type":"text","text":"seems to be a work around "},{"type":"text","text":"link","marks":[{"type":"link","attrs":{"href":"https://example.org/"}}]}]}],"version":1}

I did briefly open up the source code, but got reminded immediately that javascript isn't my language. All I noticed was that the library appears to do string matching in markdownParsing.js rather than using some kind of context aware parsing engine. Without being an expert, I suspect that is a too simplistic approach for more than the most simple use cases.

Regarding the workaround; Having to add hard paragraph breaks is not ideal, but removing those manually is at least a lot less work than fiddling with hyperlinks in Atlassians web browser interface.

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