2020-01-30 23:05:23 +02:00
|
|
|
const fountain = require('../../vendor/fountain.min.js');
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
const pluginAssets = function() {
|
2020-03-23 02:47:25 +02:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
inline: true,
|
|
|
|
mime: 'text/css',
|
|
|
|
text: `
|
|
|
|
.fountain {
|
|
|
|
font-family: monospace;
|
|
|
|
line-height: 107%;
|
|
|
|
max-width: 1000px;
|
|
|
|
margin-left: auto;
|
|
|
|
margin-right: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .title-page,
|
|
|
|
.fountain .page {
|
|
|
|
box-shadow: 0 0 5px rgba(0,0,0,0.1);
|
|
|
|
border: 1px solid #d2d2d2;
|
|
|
|
padding: 10%;
|
|
|
|
margin-bottom: 2em;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain h1,
|
|
|
|
.fountain h2,
|
|
|
|
.fountain h3,
|
|
|
|
.fountain h4,
|
|
|
|
.fountain p {
|
|
|
|
font-weight: normal;
|
|
|
|
line-height: 107%;
|
|
|
|
margin: 1em 0;
|
|
|
|
border: none;
|
|
|
|
font-size: 1em;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .bold {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .underline {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .centered {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain h2 {
|
|
|
|
text-align: right;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .dialogue p.parenthetical {
|
|
|
|
margin-left: 11%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .title-page .credit,
|
|
|
|
.fountain .title-page .authors,
|
|
|
|
.fountain .title-page .source {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .title-page h1 {
|
|
|
|
margin-bottom: 1.5em;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .title-page .source {
|
|
|
|
margin-top: 1.5em;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .title-page .notes {
|
|
|
|
text-align: right;
|
|
|
|
margin: 3em 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .title-page h1 {
|
|
|
|
margin-bottom: 1.5em;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .dialogue {
|
|
|
|
margin-left: 3em;
|
|
|
|
margin-right: 3em;
|
2023-01-16 17:46:17 +02:00
|
|
|
margin-bottom: 1em;
|
2020-03-23 02:47:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .dialogue p,
|
|
|
|
.fountain .dialogue h1,
|
|
|
|
.fountain .dialogue h2,
|
|
|
|
.fountain .dialogue h3,
|
|
|
|
.fountain .dialogue h4 {
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fountain .dialogue h1,
|
|
|
|
.fountain .dialogue h2,
|
|
|
|
.fountain .dialogue h3,
|
|
|
|
.fountain .dialogue h4 {
|
|
|
|
text-align: center;
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
2020-01-30 23:05:23 +02:00
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function renderFountainScript(markdownIt: any, content: string) {
|
2020-01-30 23:05:23 +02:00
|
|
|
const result = fountain.parse(content);
|
2020-03-10 01:24:57 +02:00
|
|
|
|
2020-01-30 23:05:23 +02:00
|
|
|
return `
|
2020-03-10 01:24:57 +02:00
|
|
|
<div class="fountain joplin-editable">
|
2020-04-09 18:47:12 +02:00
|
|
|
<pre class="joplin-source" data-joplin-language="fountain" data-joplin-source-open="\`\`\`fountain " data-joplin-source-close=" \`\`\` ">${markdownIt.utils.escapeHtml(content)}</pre>
|
2020-01-30 23:05:23 +02:00
|
|
|
<div class="title-page">
|
|
|
|
${result.html.title_page}
|
|
|
|
</div>
|
|
|
|
<div class="page">
|
|
|
|
${result.html.script}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
function plugin(markdownIt: any) {
|
|
|
|
const defaultRender = markdownIt.renderer.rules.fence || function(tokens: any[], idx: number, options: any, _env: any, self: any) {
|
2020-01-30 23:05:23 +02:00
|
|
|
return self.renderToken(tokens, idx, options);
|
|
|
|
};
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
markdownIt.renderer.rules.fence = function(tokens: any[], idx: number, options: any, env: any, self: any) {
|
2020-01-30 23:05:23 +02:00
|
|
|
const token = tokens[idx];
|
|
|
|
if (token.info !== 'fountain') return defaultRender(tokens, idx, options, env, self);
|
2020-03-10 01:24:57 +02:00
|
|
|
return renderFountainScript(markdownIt, token.content);
|
2020-01-30 23:05:23 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-10-21 01:23:55 +02:00
|
|
|
export default {
|
|
|
|
plugin,
|
|
|
|
assets: pluginAssets,
|
2020-01-30 23:05:23 +02:00
|
|
|
};
|