Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scully): support for markdown options like {:target="_blank"} #422

Merged
merged 3 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(scully): support for markdown options like {:target="_blank"}
  • Loading branch information
SanderElias committed Mar 24, 2020
commit 1b0a78caa7a3ce9837f2e9957fb0c06a437ae729
2 changes: 1 addition & 1 deletion projects/scullyio/ng-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scullyio/ng-lib",
"version": "0.0.21",
"version": "0.0.22",
"repository": {
"type": "GIT",
"url": "https://github.com/scullyio/scully/tree/master/projects/scullyio/ng-lib"
Expand Down
2 changes: 1 addition & 1 deletion scully/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scullyio/scully",
"version": "0.0.81",
"version": "0.0.83",
"description": "Scully CLI",
"repository": {
"type": "GIT",
Expand Down
1 change: 1 addition & 0 deletions scully/pluginManagement/systemPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import '../routerPlugins/defaultRouterPlugin';
import '../routerPlugins/ignoredRoutePlugin';
import '../routerPlugins/jsonRoutePlugin';
import '../renderPlugins/seoHrefCompletionPlugin';
import '../renderPlugins/customMarkdownOptions';
3 changes: 2 additions & 1 deletion scully/renderPlugins/contentRenderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {handleFile} from './content-render-utils/handleFile';
import {insertContent} from './content-render-utils/insertContent';
import {readFileAndCheckPrePublishSlug} from './content-render-utils/readFileAndCheckPrePublishSlug';
import {JSDOM} from 'jsdom';
import {customMarkdownOptions} from './customMarkdownOptions';

registerPlugin('render', 'contentFolder', contentRenderPlugin);

Expand All @@ -24,7 +25,7 @@ export async function contentRenderPlugin(html: string, route: HandledRoute) {
.split('>')[0]
.trim()
);
const additionalHTML = await handleFile(extension, fileContent);
const additionalHTML = await customMarkdownOptions(await handleFile(extension, fileContent));
const htmlWithNgAttr = addNgIdAttribute(additionalHTML, attr);
return insertContent(scullyBegin, scullyEnd, html, htmlWithNgAttr, getScript(attr));
} catch (e) {
Expand Down
28 changes: 28 additions & 0 deletions scully/renderPlugins/customMarkdownOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const customMarkdownOptions = (html: string) => {
return html.replace(/\<a[^>]*\>[^<]*\<\/a\>\{[^}]*\}/g, (val, pos) => {
const [start, rest] = val.split('{:');
const injectStr = rest.slice(0, -1);
const [initial, end] = start.split('href=');
return `${initial} ${injectStr} href=${end}`;
});
};

SanderElias marked this conversation as resolved.
Show resolved Hide resolved
// const test = `
// sdfoasjdfkl sakdfjas lkdf;askdjf as;djf asldkjf
// <a href="url">link</a>{:target="_blank" class="pepe"}
// SOME BULLSHIT STARTING TEXT
// <a href="bar">foo</a>{:target="_blank"}
// BS MIDDLE TEXT
// <a href="bar">foo</a>{:target="_blank"}
// END TEXT

// SOME BULLSHIT STARTING TEXT
// <a href="bar">foo</a>{:target="_blank"}
// BS MIDDLE TEXT
// <a href="bar">foo</a>{:target="_blank"}
// END TEXT
// `

// customMarkdownOptions(test); //?

// registerPlugin('render','customMarkdownOptions', customMarkdownOptions)