Skip to content

Commit

Permalink
fix post processor not going in proper order of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alteras1 committed Apr 27, 2024
1 parent 8a66786 commit d9394d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
11 changes: 7 additions & 4 deletions assets/bundled/bbcode-parser.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

const MD_NEWLINE_INJECT = "<!-- bbcode injected newlines -->\n\n";
const MD_NEWLINE_PRE_INJECT = "\n\n<!-- bbcode pre injected newlines -->";
const MD_NEWLINE_INJECT_COMMENT = "<!-- bbcode injected newlines -->";

const URL_REGEX =
/(http|ftp|https|upload):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])/;
Expand Down Expand Up @@ -2529,8 +2530,10 @@
* @returns post processed string
*/
function removeNewlineInjects(raw) {
const processed = raw.replaceAll(MD_NEWLINE_INJECT, "").replaceAll(MD_NEWLINE_PRE_INJECT, ""); // Remove all instances of the injected newline

const processed = raw
.replaceAll(MD_NEWLINE_INJECT, "")
.replaceAll(MD_NEWLINE_PRE_INJECT, "")
.replaceAll(MD_NEWLINE_INJECT_COMMENT, ""); // Remove all instances of the injected newline
return processed;
}

Expand All @@ -2555,10 +2558,10 @@
* @returns final processed string
*/
function postprocess(raw, data) {
let final = "";
let final = raw;
const postprocessors = [removeNewlineInjects, renderHoistedCodeBlocks];
for (const postprocessor of postprocessors) {
final = postprocessor(raw, data);
final = postprocessor(final, data);
}
return final;
}
Expand Down
2 changes: 2 additions & 0 deletions bbcode-src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const regexIndexOf = (string, regex, startpos) => {

const MD_NEWLINE_INJECT = "<!-- bbcode injected newlines -->\n\n";
const MD_NEWLINE_PRE_INJECT = "\n\n<!-- bbcode pre injected newlines -->";
const MD_NEWLINE_INJECT_COMMENT = "<!-- bbcode injected newlines -->";

const URL_REGEX =
/(http|ftp|https|upload):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])/;
Expand Down Expand Up @@ -89,6 +90,7 @@ export {
preprocessAttr,
regexIndexOf,
MD_NEWLINE_INJECT,
MD_NEWLINE_INJECT_COMMENT,
MD_NEWLINE_PRE_INJECT,
URL_REGEX,
MD_URL_REGEX,
Expand Down
12 changes: 7 additions & 5 deletions bbcode-src/utils/postprocess.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MD_NEWLINE_INJECT, MD_NEWLINE_PRE_INJECT } from "./common";
import { MD_NEWLINE_INJECT, MD_NEWLINE_INJECT_COMMENT, MD_NEWLINE_PRE_INJECT } from "./common";

/**
* Post Processing designed to fix issues with Markdown and BBCode that the parser can't fix.
Expand All @@ -8,8 +8,10 @@ import { MD_NEWLINE_INJECT, MD_NEWLINE_PRE_INJECT } from "./common";
* @returns post processed string
*/
function removeNewlineInjects(raw) {
const processed = raw.replaceAll(MD_NEWLINE_INJECT, "").replaceAll(MD_NEWLINE_PRE_INJECT, ""); // Remove all instances of the injected newline

const processed = raw
.replaceAll(MD_NEWLINE_INJECT, "")
.replaceAll(MD_NEWLINE_PRE_INJECT, "")
.replaceAll(MD_NEWLINE_INJECT_COMMENT, ""); // Remove all instances of the injected newline
return processed;
}

Expand All @@ -34,10 +36,10 @@ function renderHoistedCodeBlocks(raw, data) {
* @returns final processed string
*/
export function postprocess(raw, data) {
let final = "";
let final = raw;
const postprocessors = [removeNewlineInjects, renderHoistedCodeBlocks];
for (const postprocessor of postprocessors) {
final = postprocessor(raw, data);
final = postprocessor(final, data);
}
return final;
}

0 comments on commit d9394d4

Please sign in to comment.