From f629c810dee10c093621189d3bb80389038fce88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Thu, 11 Jul 2019 23:54:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=9B=B4=E6=94=B9=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/common/TextUtil.js | 36 +++++++++++++++++++++++++++++ public/react/src/common/educoder.js | 2 ++ 2 files changed, 38 insertions(+) create mode 100644 public/react/src/common/TextUtil.js diff --git a/public/react/src/common/TextUtil.js b/public/react/src/common/TextUtil.js new file mode 100644 index 00000000..f5dca6e5 --- /dev/null +++ b/public/react/src/common/TextUtil.js @@ -0,0 +1,36 @@ +import { bytesToSize } from 'educoder'; +export function isImageExtension(fileName) { + return fileName ? !!(fileName.match(/.(jpg|jpeg|png|gif)$/i)) : false +} + +export function markdownToHTML(oldContent, selector) { + window.$('#md_div').html('') + // markdown to html + var markdwonParser = window.editormd.markdownToHTML("md_div", { + markdown: oldContent, + emoji: true, + htmlDecode: "style,script,iframe", // you can filter tags decode + taskList: true, + tex: true, // 默认不解析 + flowChart: true, // 默认不解析 + sequenceDiagram: true // 默认不解析 + }); + const content = window.$('#md_div').html() + if (selector) { + window.$(selector).html(content) + } + return content +} + +export function appendFileSizeToUploadFile(item) { + return `${item.title}${uploadNameSizeSeperator}${item.filesize}` +} +export function appendFileSizeToUploadFileAll(fileList) { + return fileList.map(item => { + if (item.name.indexOf(uploadNameSizeSeperator) == -1) { + return Object.assign({}, item, {name: `${item.name}${uploadNameSizeSeperator}${bytesToSize(item.size)}`}) + } + return item + }) +} +export const uploadNameSizeSeperator = '  ' \ No newline at end of file diff --git a/public/react/src/common/educoder.js b/public/react/src/common/educoder.js index e25ecb9d..7a5e5bc1 100644 --- a/public/react/src/common/educoder.js +++ b/public/react/src/common/educoder.js @@ -13,6 +13,8 @@ export { updatePageParams as updatePageParams } from './RouterUti export { bytesToSize as bytesToSize } from './UnitUtil'; +export { markdownToHTML, uploadNameSizeSeperator, appendFileSizeToUploadFile, appendFileSizeToUploadFileAll, isImageExtension } from './TextUtil' + export { handleDateString, getNextHalfHourOfMoment,formatDuring } from './DateUtil' export { isDev as isDev } from './Env'