diff --git a/LICENSE b/LICENSE index fada32c..8f84c80 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2016 Jyoti Puri +Copyright (c) 2021 Walisson Rodrigo Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/config/webpack.prod.config.js b/config/webpack.prod.config.js index c9130fa..4e65848 100644 --- a/config/webpack.prod.config.js +++ b/config/webpack.prod.config.js @@ -1,19 +1,16 @@ var path = require("path"); var webpack = require("webpack"); -const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); module.exports = { devtool: "source-map", + mode: 'production', entry: ["./js/index"], output: { path: path.join(__dirname, "../lib"), - filename: "draftjs-to-markdown.js", - library: "draftjsToMarkdown", + filename: "draftjs-to-markdown-v2.js", + library: "draftjsToMarkdownV2", libraryTarget: "umd" }, - optimization: { - minimizer: [new UglifyJsPlugin()] - }, plugins: [ new webpack.DefinePlugin({ "process.env": { diff --git a/js/index.js b/js/index.js index c99ace7..a03a99f 100644 --- a/js/index.js +++ b/js/index.js @@ -1,56 +1,58 @@ -import { isEmptyString, forEach, isList } from './common'; +import {isEmptyString, forEach, isList} from './common'; /** * Mapping block-type to corresponding markdown symbol. */ const defaultBlockTypesMapping = { - unstyled: '', - 'header-one': '# ', - 'header-two': '## ', - 'header-three': '### ', - 'header-four': '#### ', - 'header-five': '##### ', - 'header-six': '###### ', - 'unordered-list-item': '- ', - 'ordered-list-item': '1. ', - blockquote: '> ', - code: ' ', + unstyled: '', + 'header-one': '# ', + 'header-two': '## ', + 'header-three': '### ', + 'header-four': '#### ', + 'header-five': '##### ', + 'header-six': '###### ', + 'unordered-list-item': '- ', + 'ordered-list-item': '1. ', + blockquote: '> ', + code: ' ', }; /** * Function to check if the block is an atomic entity block. */ function isAtomicBlock(block) { - if (block.entityRanges.length > 0 && isEmptyString(block.text)) { - return true; - } - return false; + if (block.entityRanges.length > 0 && isEmptyString(block.text)) { + return true; + } + return false; } /** * Function will return markdown for Entity. */ function getEntityMarkdown(entityMap, entityKey, text, customEntityTransform) { - const entity = entityMap[entityKey]; - if (typeof customEntityTransform === 'function') { - const html = customEntityTransform(entity, text); - if (html) { - return html; - } - } - if (entity.type === 'MENTION') { - return `[${text}](${entity.data.url})`; - } - if (entity.type === 'LINK') { - return `[${text}](${entity.data.url})`; - } - if (entity.type === 'IMAGE') { - return `![${entity.data.alt || ''}](${entity.data.src})`; - } - if (entity.type === 'EMBEDDED_LINK') { - return `