Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 1 addition & 4 deletions src/components/Editor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import MarkdownIt from 'markdown-it';
import ReactMdEditor from 'react-markdown-editor-lite';
import 'react-markdown-editor-lite/lib/index.css';

import { ImageProvider, compressImage } from 'core/api/img';
import { mdParser } from './mdParser';

// Initialize a markdown parser
const mdParser = new MarkdownIt();
const api = new ImageProvider();

export function MdEditor(Props) {

async function onImageUpload(file) {
const imageFile = await compressImage(file);
const formData = new FormData();
Expand Down
35 changes: 35 additions & 0 deletions src/components/Editor/mdParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import MarkdownIt from 'markdown-it';

// Initialize a markdown parser
export const mdParser = new MarkdownIt();

// save multiple breaks, see: https://github.com/markdown-it/markdown-it/issues/211#issuecomment-508380611
const defaultParagraphRenderer =
mdParser.renderer.rules.paragraph_open ||
((tokens, idx, options, env, self) => self.renderToken(tokens, idx, options));
mdParser.renderer.rules.paragraph_open = function (
tokens,
idx,
options,
env,
self,
) {
let result = '';
if (idx > 1) {
const inline = tokens[idx - 2];
const paragraph = tokens[idx];
if (
inline.type === 'inline' &&
inline.map &&
inline.map[1] &&
paragraph.map &&
paragraph.map[0]
) {
const diff = paragraph.map[0] - inline.map[1];
if (diff > 0) {
result = '<br>'.repeat(diff);
}
}
}
return result + defaultParagraphRenderer(tokens, idx, options, env, self);
};
3 changes: 1 addition & 2 deletions src/pages/post/[publicKey]/PostContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const PostContent = ({
t,
}) => {
const myPublicKey = useReadonlyMyPublicKey();

return (
<div className={styles.postContent}>
<div className={styles.postHeader}>
Expand Down Expand Up @@ -86,7 +85,7 @@ const PostContent = ({
),
}}
>
{content ?? ''}
{content ? content.replace(/\n\n/gi, "&nbsp; \n\n") : ''}
</ReactMarkdown>
</div>

Expand Down