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

codly:0.1.0 #217

Merged
merged 8 commits into from
Nov 6, 2023
Merged

codly:0.1.0 #217

merged 8 commits into from
Nov 6, 2023

Conversation

Dherse
Copy link
Contributor

@Dherse Dherse commented Nov 4, 2023

I am submitting

  • a new package
  • an update for a package

Description: Pretty code blocks for Typst. Highly customizable and easy to use.

I have read and followed the submission guidelines and, in particular, I

  • selected a name in conformance with the guidelines
  • added a typst.toml file with all required keys
  • added a README.md with documentation for my package
  • have chosen a license and added a LICENSE file or linked one in my README.md
  • ensured that my submission does not infringe upon the rights of a third party
  • tested my package locally on my system and it worked
  • named this PR as name:version of the submitted package
  • agree that my package will not be removed without good reason

@bastienvoirin
Copy link

Hi @Dherse, I was just about to submit a package named differre which displays added lines (prefixed with + ) on a green background and deleted lines (prefixed with - ) on a red background, when the lang is prefixed with diff- 😅

I think this feature would fit nicely into your codly package, so here is the snippet I have written so far:

#let diff(
  prefix: true,
  color-add: color.rgb("#2ecc403f"),
  color-del: color.rgb("#ff41363f"),
  document
) = {
  show raw: it => {
    if it.has("block") and it.block {
      stack(dir: ttb, ..if it.lang != none and it.lang.starts-with("diff-") {
        it.lines.map(line => box(
          width: 100%,
          height: 1em*3/2,
          inset: (x: 1em*1/6, y: 1em*1/3),
          fill:
            if line.text.starts-with("+ ") { color-add }
            else if line.text.starts-with("- ") { color-del }
            else { none },
          [
            #if prefix {box(width: 1em*7/6, {
              if line.text.starts-with("+ ") { text(color-add, raw("+")) }
              else if line.text.starts-with("- ") { text(color-del, raw("-")) }
            })}#box[
              #raw(
                if line.text.len() >= 2 { line.text.slice(2) } else { "" },
                block: false,
                lang: it.lang.trim("diff-", at: start)
              )
            ]
          ]
        ))
      } else {
        it.lines.map(line => box(
          width: 100%,
          height: 1em*3/2,
          inset: (x: 1em*1/6, y: 1em*1/3),
          line
        ))
      })
    } else {
      if it.lines.len() > 0 {
        let line = it.lines.at(0)
        if it.lang != none and it.lang.starts-with("diff-") {
          box(
            inset: (x: 1em*1/6, y: 0em),
            outset: (y: 1em*1/3),
            fill:
              if line.text.starts-with("+ ") { color-add }
              else if line.text.starts-with("- ") { color-del }
              else { none },
            [
              #if prefix {box(width: 1em*7/6, {
                if line.text.starts-with("+ ") { text(color-add, raw("+")) }
                else if line.text.starts-with("- ") { text(color-del, raw("-")) }
              })}#box[
                #raw(
                  if line.text.len() >= 2 { line.text.slice(2) } else { "" },
                  block: false,
                  lang: if it.lang != none and it.lang.starts-with("diff-") {
                    it.lang.trim("diff-", at: start)
                  } else {
                    none
                  }
                )
              ]
            ]
          )
        } else {
          box(
            inset: (x: 1em*1/6, y: 0em),
            outset: (y: 1em*1/3),
            line.body
          )
        }
      }
    }
  }
  document
}

Besides a font size reduction when the lang starts with diff- and some code quality improvements, I am ready to submit differre if you think the diff feature does not belong in codly 🙂

@Dherse
Copy link
Contributor Author

Dherse commented Nov 5, 2023

@bastienvoirin I am very much open to it, I just need to look at how I can best implement it into the existing code ;)

packages/preview/codly/0.1.0/README.md Outdated Show resolved Hide resolved
packages/preview/codly/0.1.0/codly.typ Show resolved Hide resolved
packages/preview/codly/0.1.0/example/main.typ Outdated Show resolved Hide resolved
@laurmaedje laurmaedje added the new A new package submission. label Nov 6, 2023
@Dherse
Copy link
Contributor Author

Dherse commented Nov 6, 2023

okay @laurmaedje I have resolved the issues.

@Dherse
Copy link
Contributor Author

Dherse commented Nov 6, 2023

Thanks to everyone for commenting

@laurmaedje laurmaedje merged commit dcbb9f6 into typst:main Nov 6, 2023
@laurmaedje
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new A new package submission.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants