1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

fixed text blocks

This commit is contained in:
Fedor Katurov 2019-11-27 10:01:10 +07:00
parent 1169a90553
commit e3bfacddcb
2 changed files with 8 additions and 3 deletions

View file

@ -1,7 +1,7 @@
import React, { FC } from 'react';
import { INode } from '~/redux/types';
import path from 'ramda/es/path';
import { formatText } from '~/utils/dom';
import { formatTextParagraphs } from '~/utils/dom';
import * as styles from './styles.scss';
interface IProps {
@ -12,7 +12,7 @@ const NodeTextBlock: FC<IProps> = ({ node }) => (
<div
className={styles.text}
dangerouslySetInnerHTML={{
__html: formatText(path(['blocks', 0, 'text'], node)),
__html: formatTextParagraphs(path(['blocks', 0, 'text'], node)),
}}
/>
);

View file

@ -94,9 +94,14 @@ export const formatText = (text: string): string =>
.replace(/:\|--\|/gim, '://')
.split('\n')
.filter(el => el.trim().length)
// .map(el => `<p>${el}</p>`)
.join('\n');
export const formatTextParagraphs = (text: string): string =>
text
.split('\n')
.map(str => `<p>${str}</p>`)
.join('\n');
export const findBlockType = (line: string): ValueOf<typeof COMMENT_BLOCK_TYPES> => {
const match = Object.values(COMMENT_BLOCK_DETECTORS).find(detector => line.match(detector.test));
return (match && match.type) || COMMENT_BLOCK_TYPES.TEXT;