diff --git a/pom.xml b/pom.xml
index e65355ec88d1b8feedc386a3ad0e2cb856e0ff0a..6c54e5266a771ff399823a55d94086eca3501fce 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,19 @@
MD2File
Markdown to ms word, pdf, html
https://git.oschina.net/cevin15/MD2File
- 4.0.0
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 7
+ 7
+
+
+
+
+ 4.0.0
com.youbenzi
MD2File
1.0.2
diff --git a/src/main/java/com/youbenzi/md2/export/FileFactory.java b/src/main/java/com/youbenzi/md2/export/FileFactory.java
index 1e6c5899e36e56fb06556e4c162d6d993c7b9ceb..5f2e87fec05e62f8b7d13760d09cfdeddca16e97 100644
--- a/src/main/java/com/youbenzi/md2/export/FileFactory.java
+++ b/src/main/java/com/youbenzi/md2/export/FileFactory.java
@@ -60,10 +60,34 @@ public class FileFactory {
return outputFilePath.substring(i + 1);
}
+ //将md文档去掉格式转为纯文本内容
+ public static void convertAndSaveMarkdownAsPlainText(String markdown, String filePath) {
+ StringBuilder plainText = new StringBuilder();
+ String[] lines = markdown.split("\\n");
+
+ for (String line : lines) {
+ if (line.startsWith("#")) {
+ plainText.append(line.replaceAll("#", "")).append("\n");
+ } else if (line.startsWith("*")) {
+ plainText.append(line.replaceAll("\\*", "")).append("\n");
+ } else {
+ plainText.append(line).append("\n");
+ }
+ }
+
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
+ writer.write(plainText.toString());
+ } catch (IOException e) {
+ System.err.println("Error writing to file: " + e.getMessage());
+ }
+ }
+
+
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
// WordFactory.produce("#大标题\n###小标题\n```\npublic void main()\n system.out.println(\"hello\")\n```\n123123\n```\n正文,这里是**_正文_**测试测试**粗体**哦\n> 这里是引用,**粗体**_斜体__**粗斜合一**_**123_12", "/Users/cevin/Downloads/simple4.docx");
- FileFactory.produce(new File("/Users/cevin/Downloads/测试.md"), "/Users/cevin/Downloads/simple.docx");
+// FileFactory.produce(new File("/Users/cevin/Downloads/测试.md"), "/Users/cevin/Downloads/simple.docx");
// WordFactory.produce("> ###123123\n> 123","/Users/cevin/Downloads/simple2.docx");
+ FileFactory.convertAndSaveMarkdownAsPlainText("# Hello world","D:/tmp/simple.docx");
}
}