Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vf-core-mirror
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
embl.org
vf-core-mirror
Commits
ff1b8976
Commit
ff1b8976
authored
5 years ago
by
Ken Hawkins
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup
parent
330b1a9b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fractal.js
+2
-0
2 additions, 0 deletions
fractal.js
tools/vf-frctl-extensions/markdown.js
+0
-16
0 additions, 16 deletions
tools/vf-frctl-extensions/markdown.js
tools/vf-frctl-theme/src/extensions/markdown.js
+53
-52
53 additions, 52 deletions
tools/vf-frctl-theme/src/extensions/markdown.js
with
55 additions
and
68 deletions
fractal.js
+
2
−
0
View file @
ff1b8976
...
...
@@ -30,7 +30,9 @@ module.exports = {
},
paths
:
[
"
./components
"
],
filters
:
{
// {{ "## Parse me" | marked }}
marked
:
function
(
string
)
{
const
renderMarkdown
=
require
(
'
marked
'
);
return
renderMarkdown
(
string
);
},
// A filter and non-async version of frctl's context extension from
...
...
This diff is collapsed.
Click to expand it.
tools/vf-frctl-extensions/markdown.js
+
0
−
16
View file @
ff1b8976
...
...
@@ -83,19 +83,3 @@ module.exports = function(fractal){
return
new
MarkdownExtenstion
();
};
/*
'use strict';
const renderMarkdown = require('marked');
const nunjucks = require('nunjucks');
module.exports = function(theme, env, app, fractal){
};
*/
This diff is collapsed.
Click to expand it.
tools/vf-frctl-theme/src/extensions/markdown.js
+
53
−
52
View file @
ff1b8976
...
...
@@ -14,73 +14,74 @@ Confused? Rule of thumb: if you use a component to make other components, name i
</div>
*/
// Note: The structure of this file's paramaters are slightly different so we can't easily reuse the /tools/vf-frctl-extensions/markdown.js
module
.
exports
=
function
(
theme
,
env
,
app
,
fractal
){
// port of https://github.com/zephraph/nunjucks-markdown
// Licence: https://github.com/zephraph/nunjucks-markdown/blob/master/LICENSE
function
MarkdownExtenstion
()
{
// port of https://github.com/zephraph/nunjucks-markdown
// Licence: https://github.com/zephraph/nunjucks-markdown/blob/master/LICENSE
function
MarkdownExtenstion
()
{
this
.
tags
=
[
'
markdown
'
];
this
.
tags
=
[
'
markdown
'
];
this
.
parse
=
function
(
parser
,
nodes
,
lexer
)
{
var
tok
=
parser
.
nextToken
();
this
.
parse
=
function
(
parser
,
nodes
,
lexer
)
{
var
tok
=
parser
.
nextToken
();
// Parse the markdown tag and collect any arguments
var
args
=
parser
.
parseSignature
(
null
,
true
);
parser
.
advanceAfterBlockEnd
(
tok
.
value
);
// Parse the markdown tag and collect any arguments
var
args
=
parser
.
parseSignature
(
null
,
true
);
parser
.
advanceAfterBlockEnd
(
tok
.
value
);
// If arguments, return the fileTag constructed node
if
(
args
.
children
.
length
>
0
)
return
new
nodes
.
CallExtension
(
this
,
'
fileTag
'
,
args
);
// If arguments, return the fileTag constructed node
if
(
args
.
children
.
length
>
0
)
return
new
nodes
.
CallExtension
(
this
,
'
fileTag
'
,
args
);
// Otherwise parse until the close block and move the parser to the next position
var
body
=
parser
.
parseUntilBlocks
(
'
endmarkdown
'
);
// Otherwise parse until the close block and move the parser to the next position
var
body
=
parser
.
parseUntilBlocks
(
'
endmarkdown
'
);
// I found Nunjucks to be incredibly convoluted on how to just get some data into the BlockTag function,
// this finally worked by faking another template node.
var
tabStart
=
new
nodes
.
NodeList
(
0
,
0
,
[
new
nodes
.
Output
(
0
,
0
,
[
new
nodes
.
TemplateData
(
0
,
0
,
(
tok
.
colno
-
1
))])]);
// I found Nunjucks to be incredibly convoluted on how to just get some data into the BlockTag function,
// this finally worked by faking another template node.
var
tabStart
=
new
nodes
.
NodeList
(
0
,
0
,
[
new
nodes
.
Output
(
0
,
0
,
[
new
nodes
.
TemplateData
(
0
,
0
,
(
tok
.
colno
-
1
))])]);
parser
.
advanceAfterBlockEnd
();
parser
.
advanceAfterBlockEnd
();
// Return the constructed blockTag node
return
new
nodes
.
CallExtension
(
this
,
'
run
'
,
args
,
[
body
,
tabStart
]);
};
// Return the constructed blockTag node
return
new
nodes
.
CallExtension
(
this
,
'
run
'
,
args
,
[
body
,
tabStart
]);
};
// Markdown rendering for the file tag. Use the nunjucks.render function to render
// the actual contents of the file. Pass the results through the markdown renderer.
this
.
fileTag
=
function
(
environment
,
file
)
{
return
new
nunjucks
.
runtime
.
SafeString
(
renderMarkdown
(
env
.
render
(
file
,
environment
.
ctx
)));
}
// Markdown rendering for the file tag. Use the nunjucks.render function to render
// the actual contents of the file. Pass the results through the markdown renderer.
this
.
fileTag
=
function
(
environment
,
file
)
{
return
new
nunjucks
.
runtime
.
SafeString
(
renderMarkdown
(
env
.
render
(
file
,
environment
.
ctx
)));
}
// Markdown rendering for the block. Pretty simple, just get the body text and pass
// it through the markdown renderer.
this
.
run
=
function
(
context
,
body
,
tabStart
)
{
var
body
=
body
();
var
spacesRegex
=
/^
[\s]
+/
;
var
tabStart
=
tabStart
();
// The column postion of the {% markdown %} tag.
if
(
tabStart
>
0
)
{
// If the {% markdown %} tag is tabbed in, normalize the content to the same depth.
body
=
body
.
split
(
/
\r?\n
/
);
// Split into lines.
body
=
body
.
map
(
function
(
line
)
{
var
startSpaces
=
line
.
match
(
spacesRegex
);
if
(
startSpaces
&&
startSpaces
[
0
].
length
>=
tabStart
)
{
// If the content is not at the same or greater tab depth, do nothing..
return
line
.
slice
(
tabStart
);
// Subtract the column postion from the start of the string.
}
else
if
(
startSpaces
)
{
return
line
.
slice
(
startSpaces
[
0
].
length
);
}
else
{
return
line
;
}
});
body
=
body
.
join
(
"
\n
"
);
// Rejoin into one string.
}
return
new
nunjucks
.
runtime
.
SafeString
(
renderMarkdown
(
body
));
// Markdown rendering for the block. Pretty simple, just get the body text and pass
// it through the markdown renderer.
this
.
run
=
function
(
context
,
body
,
tabStart
)
{
var
body
=
body
();
var
spacesRegex
=
/^
[\s]
+/
;
var
tabStart
=
tabStart
();
// The column postion of the {% markdown %} tag.
if
(
tabStart
>
0
)
{
// If the {% markdown %} tag is tabbed in, normalize the content to the same depth.
body
=
body
.
split
(
/
\r?\n
/
);
// Split into lines.
body
=
body
.
map
(
function
(
line
)
{
var
startSpaces
=
line
.
match
(
spacesRegex
);
if
(
startSpaces
&&
startSpaces
[
0
].
length
>=
tabStart
)
{
// If the content is not at the same or greater tab depth, do nothing..
return
line
.
slice
(
tabStart
);
// Subtract the column postion from the start of the string.
}
else
if
(
startSpaces
)
{
return
line
.
slice
(
startSpaces
[
0
].
length
);
}
else
{
return
line
;
}
});
body
=
body
.
join
(
"
\n
"
);
// Rejoin into one string.
}
return
new
nunjucks
.
runtime
.
SafeString
(
renderMarkdown
(
body
));
}
env
.
engine
.
addExtension
(
'
markdown
'
,
new
MarkdownExtenstion
());
}
env
.
engine
.
addExtension
(
'
markdown
'
,
new
MarkdownExtenstion
());
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment