Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Gap-text and gap-text-dropdown ignore markdown line breaks #272

Closed
2 tasks done
Rllyyy opened this issue Apr 20, 2023 · 0 comments
Closed
2 tasks done

[BUG] Gap-text and gap-text-dropdown ignore markdown line breaks #272

Rllyyy opened this issue Apr 20, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Rllyyy
Copy link
Owner

Rllyyy commented Apr 20, 2023

GapText.css and GapTextDropdown.css

.question-gap-text p,
.correction-gap-text p,
.question-gap-text div,
.correction-gap-text div,
.question-gap-text input,
.correction-gap-text input {
  white-space: pre-wrap;
- display: inline;
}

The next part somewhat relates to #201

function textWithBlanks(text: string): string {
  //rehype-raw allows the passing of html elements from the json file (when the users set a <p> text for example)
  //remarkGfm draws markdown tables
  const htmlString = ReactDOMServer.renderToString(
    <ReactMarkdown
      children={text}
      linkTarget='_blank'
      transformLinkUri={normalizeLinkUri}
      rehypePlugins={[rehypeRaw, rehypeKatex]}
      remarkPlugins={[remarkGfm, remarkMath]}
    />
  );

  //Split the html notes where the input should be inserted
  const htmlStringSplit = htmlString.split("[]");

  //Insert the input marker between the array elements but not at the end
  const res = htmlStringSplit.map((line, index) => {
    if (index < htmlStringSplit.length - 1) {
      return line.concat(
        ReactDOMServer.renderToString(<input className={"input-wrapper"} id={`input-wrapper-${index}`} />)
      );
    } else {
      return line;
    }
  });

  //Combine the array to one string again
  const joinedElements = res.join("");

  //Remove jsx specific html syntax
  const exportHTML = joinedElements
    .replaceAll("&lt;", "<")
    .replaceAll("&gt;", ">")
    .replaceAll("&quot;", '"')
    .replaceAll('data-reactroot=""', "");

  // Sanitize the result
  return DOMPurify.sanitize(exportHTML, {
    FORBID_TAGS: forbiddenTags,
    FORBID_ATTR: forbiddenAttributes,
  });
}

Todo:

  • replace the render in the useLayoutEffect of gap-text and gap-text-dropdown with just attaching events
  • replace the replaceAll with regex
@Rllyyy Rllyyy added the bug Something isn't working label Apr 20, 2023
@Rllyyy Rllyyy self-assigned this Apr 20, 2023
Rllyyy added a commit that referenced this issue Apr 22, 2023
@Rllyyy Rllyyy closed this as completed Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant