Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Auto Linking only links first item in a document #17

Open
MatthewCallis opened this issue Nov 15, 2017 · 0 comments
Open

Auto Linking only links first item in a document #17

MatthewCallis opened this issue Nov 15, 2017 · 0 comments

Comments

@MatthewCallis
Copy link

if (missingLinks && missingLinks.length > 0) {
var pairs = _.chunk(missingLinks, 2);
_.forEach(pairs, (pair) => {
let slug = this._storageProvider.titleToSlug(pair[1]);
document.markdown = document.markdown.replace(pair[0], pair[0].replace("()", "(/" + slug + ")"));
});
}

I updated this code to (but also moved to using slugify):

      missingLinks.forEach((link) => {
        const title = link.substr(1).slice(0, -3);
        const pairSlug = slugify(title, { lower: true });
        document.markdown = document.markdown.replace(link, `[${title}](/${pairSlug})`);
      });

Also needed to make this RegEx a global search:

this._missingLinkRegex = /\[(.*)\]\(\)/;

this._missingLinkRegex = /\[(.*)\]\(\)/g;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant