Skip to content

implement tables#52

Open
CrowdHailer wants to merge 1 commit into
lpil:mainfrom
CrowdHailer:tables
Open

implement tables#52
CrowdHailer wants to merge 1 commit into
lpil:mainfrom
CrowdHailer:tables

Conversation

@CrowdHailer

Copy link
Copy Markdown
Contributor

Just used the available tests as mentioned in #36

Wraps up running the formatter. let me know if you want that on a separate commit or branch.

@CrowdHailer

Copy link
Copy Markdown
Contributor Author

Ah, I think I'm on the wrong gleam version that's what's making the reformat happen.

@lpil lpil left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Wow, fantastic work! Thank you!!

I've added some notes inline, mostly around performance. This code will be in the hot path for lots of applications, so performance is really important.

I also pushed a commit that run the formatter.

Comment thread src/jot.gleam Outdated

fn table_row_cells(line: String) -> Option(List(String)) {
let line = string.trim(line)
case string.starts_with(line, "|") {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Prefer pattern matching to starts_with + drop_start 🙏

Comment thread src/jot.gleam Outdated
}
}

fn split_table_row(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This function is extremely slow due to repeatedly splitting a string into graphemes and joining them back into a string. Please use splitters and string pattern matching instead 🙏

Comment thread src/jot.gleam Outdated
string.to_graphemes(cell)
|> list.all(fn(char) { char == "-" || char == ":" })
}
})

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Use string pattern matching please instead of converting to graphemes etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I really need to remember most of the time grapheme is not a crucial detail

Comment thread src/jot.gleam Outdated
#(Some(drop_empty_text(caption)), in)
}

fn take_caption_lines(in: String, lines: List(String)) -> #(String, String) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think this function is finding the first \n\n. Couldn't we use string.split_once for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm actually looking for any line indentation

@CrowdHailer

Copy link
Copy Markdown
Contributor Author

I've force pushed a new version. Have kept most function names but switch quite a few things.

  • TableAlignment is pulled at parsing time
  • Tried to make the caption code clearer.
  • Switched to use splitters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants