2019-01-29 22:12:48 -08:00
|
|
|
import parser from './parser';
|
2019-01-29 21:51:30 -08:00
|
|
|
import { MfmForest } from './types';
|
2019-01-29 20:47:58 -08:00
|
|
|
import { normalize } from './normalize';
|
2018-11-20 12:11:00 -08:00
|
|
|
|
2018-12-20 02:41:04 -08:00
|
|
|
export default (source: string, plainText = false): MfmForest => {
|
|
|
|
if (source == null || source == '') {
|
|
|
|
return null;
|
|
|
|
}
|
2018-11-20 12:11:00 -08:00
|
|
|
|
2019-01-29 22:12:48 -08:00
|
|
|
const raw = plainText ? parser.plain.tryParse(source) : parser.root.tryParse(source) as MfmForest;
|
2019-01-29 20:47:58 -08:00
|
|
|
return normalize(raw);
|
2018-11-20 12:11:00 -08:00
|
|
|
};
|