Skip to content

Conversation

@samuelfangjw
Copy link
Contributor

@samuelfangjw samuelfangjw commented Aug 6, 2021

Closes #591

  • Accounted for possibility that "@xxx" is not followed by newline character.
  • Replaced SHORT_SPACE and SHORT_SPACE_ALLOW_BREAK with newline character in non-pdf versions.
  • Removed dead code from processSnippetJs

EDIT:

  • Set default transformation of relevant xml tags to empty string
  • Set transformation of relevant tags in pdf version to "@xxx" and "@yyy"
@TobiasWrigstad
Copy link
Collaborator

Thank you @samuelfangjw!

However, in hindsight -- would it not be better to bypass the transformation from XML tags to @xxx, etc.? initially, I used a simpler marker directly in the code in the snippets, but then we moved to a proper XML tag.

@samuelfangjw
Copy link
Contributor Author

Thank you @samuelfangjw!

However, in hindsight -- would it not be better to bypass the transformation from XML tags to @xxx, etc.? initially, I used a simpler marker directly in the code in the snippets, but then we moved to a proper XML tag.

Agreed! It would be much neater that way. I originally didn't want to make any unnecessary changes that might affect the pdf version (while we are trying to get the book published), hence this ugly stopgap solution.

I took a quick look, I believe bypassing the transformation may not be as simple as it seems, since in the pdf version "@yyy" is transformed into either separator(line 253) or seperator2(line 401) depending on context, so we would have to transform the tag into some kind of placeholder value anyways (might be wrong here).

However, seems like it would be pretty simple to limit the transformation of XML tags to just the pdf version for now. Would this be better?

I'll take a closer look at this and make any necessary changes tomorrow!

jsRunSnippet = jsSnippet;
}
}
const codeArr = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code, variable not used

SHORT_SPACE_AND_ALLOW_BREAK: "@yyy" // will be replaced in processSnippet
};

export const replaceTagWithSymbol = (node, writeTo, type = "default") => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parameter type. SHORT_SPACE and SHORT_SPACE_AND_ALLOW_BREAK are replaced if type === "pdf"

@samuelfangjw
Copy link
Contributor Author

samuelfangjw commented Aug 7, 2021

Hi @TobiasWrigstad, I've made some changes:

  • Default transformation of SHORT_SPACE and SHORT_SPACE_AND_ALLOW_BREAK is now an empty string.
  • For the pdf version, tags are transformed into "@xxx" and "@yyy", which are then handled in processSnippetPdf.

I think it would be great if we could get rid of the use of the placeholder values "@xxx" and "@yyy" entirely, but I feel it might be more trouble than it's worth at this point (Not a straightforward swap since "@yyy" is replaced either by separator or seperator2 depending on context. I believe we would have to add a check for whether the parent node has EVAL === "no" || LATEX === "yes", which I feel might add more complexity rather than simplify things).

Could you kindly help to review the PR, thanks in advance! I've also attached the pdf version created by yarn pdf so we can verify any changes.

sicpjs.pdf

@TobiasWrigstad
Copy link
Collaborator

Great @samuelfangjw! I will be able to look at this later today.

SHORT_SPACE: "@xxx", // will be replaced in processSnippet depending on rendering target (PDF, HTML, etc.)
SHORT_SPACE_AND_ALLOW_BREAK: "@yyy", // will be replaced in processSnippet depending on rendering target (PDF, HTML, etc.)
SHORT_SPACE: "",
SHORT_SPACE_AND_ALLOW_BREAK: "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to replace these with "\n" right here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, wait. That's the effect of replacing the tag by "", presumably.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @TobiasWrigstad for the review! Yes, I would have thought "\n" would have been more appropriate here, but it seems to add an extra line break (replaced by two blank lines instead of one).

Original: replace by "@xxx":
Screenshot 2021-08-08 at 7 08 01 AM

Replace with "\n":
Screenshot 2021-08-08 at 7 08 45 AM

Replace with "":
Screenshot 2021-08-08 at 7 09 13 AM

@TobiasWrigstad
Copy link
Collaborator

I made some comments above and then deleted them. I made a very stupid mistake and was looking at another file than yours dues to browser renaming it on download...

Copy link
Collaborator

@TobiasWrigstad TobiasWrigstad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've compared the right two pdfs now :) This is great.

@samuelfangjw samuelfangjw merged commit 710f2cd into source-academy:master Aug 7, 2021
@samuelfangjw samuelfangjw deleted the fix-591-again branch August 7, 2021 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants