MobX based editing

This commit is contained in:
Jori Lallo
2016-06-02 22:04:33 -07:00
parent aac20341f7
commit e6c7e95115
26 changed files with 436 additions and 185 deletions

View File

@@ -21,12 +21,12 @@ router.post('documents.info', auth({ require: false }), async (ctx) => {
// Don't expose private documents outside the team
if (document.private) {
if (!ctx.state.user) throw httpErrors.NotFound();
// if (!ctx.state.user) throw httpErrors.NotFound();
const team = await ctx.state.user.getTeam();
if (document.teamId !== team.id) {
if (!document) throw httpErrors.NotFound();
}
// const team = await ctx.state.user.getTeam();
// if (document.teamId !== team.id) {
// if (!document) throw httpErrors.NotFound();
// }
ctx.body = {
data: await presentDocument(document, true),

View File

@@ -7,7 +7,7 @@ import {
import {
convertToMarkdown,
truncateMarkdown,
} from '../utils/markdown';
} from '../../src/utils/markdown';
import Atlas from './Atlas';
import Team from './Team';
import User from './User';

View File

@@ -1,58 +0,0 @@
import slug from 'slug';
import truncate from 'truncate-html';
import marked, { Renderer } from 'marked';
import highlight from 'highlight.js';
slug.defaults.mode ='rfc3986';
const renderer = new Renderer();
renderer.code = (code, language) => {
const validLang = !!(language && highlight.getLanguage(language));
const highlighted = validLang ? highlight.highlight(language, code).value : code;
return `<pre><code class="hljs ${language}">${highlighted}</code></pre>`;
};
renderer.heading = (text, level) => {
const headingSlug = slug(text);
return `
<h${level}>
<a name="${headingSlug}" class="anchor" href="#${headingSlug}">
<span class="header-link">&nbsp;</span>
</a>
${text}
</h${level}>
`;
},
marked.setOptions({
renderer: renderer,
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: true,
});
// TODO: This is syncronous and can be costly,
// should be performed outside http request
const convertToMarkdown = (text) => {
return marked(text);
};
truncate.defaultOptions = {
stripTags: false,
ellipsis: '...',
decodeEntities: false,
excludes: ['h1', 'pre', ],
};
const truncateMarkdown = (text, length) => {
const html = convertToMarkdown(text);
return truncate(html, length);
};
export {
convertToMarkdown,
truncateMarkdown,
};