Parse hashtags from string
npm install @sphido/hashtagsSearch Markdown for hashtags and replaces them with a links #hashtag code.
``bash`
yarn add @sphido/hashtags
Function getHashtags() searches the string for all hashtags and returns them as an array.content
The input parameter is expected in Markdown format, function automatically skips
preformatted text in Markdown syntax.
`javascript
import {getHashtags} from '@sphido/hashtags';
const tags = getHashtags('#one #two #three color: #red');`
console.log(tags); // will be ['#one', '#two', '#three'];
Function tagsToMarkdown() expect at last two parameters on the input - content and tags#hash
Replace hashtags with Markdown syntax for links
`javascript
import {getPages, allPages, readFile} from '@sphido/core';
import {getHashtags, tagsToMarkdown} from '@sphido/hashtags';
const pages = await getPages({path: 'content'});
for (const page of allPages(pages)) {
page.content = await readFile(page.path);
page.tags = getHashtags(page.content);
//
page.content = tagsToMarkdown(page.content, page.tags);
}
`
Function hashtags() search for all hashtags in page.content.page.content
In case that property is empty, function will load filepage.tags
content automatically. All found tags are then stored in a #hash
property as an array. Function will also automatically replace hashtags to
Markdown syntax for links .
`javascript
import {getPages, allPages} from '@sphido/core';
import {hashtags} from '@sphido/hashtags';
const pages = await getPages({path: 'content'}, hashtags);
for (const page of allPages(pages)) {
console.log(page.tags, page.content);
}
``