Skip to content

Commit

Permalink
refactor: make rawType case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Oct 19, 2024
1 parent ae80014 commit 333bb06
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ui/src/class/contentExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ContentExporter {
(type) => type.type === content.rawType?.toLowerCase(),
)?.extension || "";
} else if (exportType === "markdown") {
if (content.rawType === "html") {
if (content.rawType?.toLowerCase() === "html") {
const converter = ConverterFactory.getConverter("html", "markdown");
exportContent = converter.convert(post, content);
} else {
Expand Down
7 changes: 5 additions & 2 deletions ui/src/class/postOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ export class PostOperations {
return;
}

if (content.rawType === toType) {
if (content.rawType.toLowerCase() === toType) {
Toast.warning(`当前文档已经是 ${toType} 格式,已忽略转换`);
return;
}

const converter = ConverterFactory.getConverter(content.rawType, toType);
const converter = ConverterFactory.getConverter(
content.rawType.toLowerCase(),
toType,
);

const convertedContent = converter.convert(post, content);

Expand Down
4 changes: 2 additions & 2 deletions ui/src/utils/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function convertPostContentToMarkdown(
content: ContentWrapper,
needsFrontMatter?: boolean,
): string {
if (content.rawType === "markdown") {
if (content.rawType?.toLowerCase() === "markdown") {
return content.raw || "";
}

Expand Down Expand Up @@ -38,7 +38,7 @@ export function convertPostContentToMarkdown(
}

export function convertPostContentToHTML(content: ContentWrapper): string {
if (content.rawType === "html") {
if (content.rawType?.toLowerCase() === "html") {
return content.raw || "";
}

Expand Down

0 comments on commit 333bb06

Please sign in to comment.