Skip to content

How can I line-wrap code blocks rather than having to scroll it. #260

Answered by gonzalezreal
NunoLemos101 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @NunoLemos101,

You can use the markdownBlockStyle(_:body:) modifier to replace a specific block style on the current Theme.

To achieve the desired effect, you should replace the current codeBlock style with a new one that does not use a ScrollView. Here is an example:

Markdown("...")
  .markdownBlockStyle(\.codeBlock) { configuration in
    configuration.label
      .fixedSize(horizontal: false, vertical: true)
      .relativeLineSpacing(.em(0.225))
      .markdownTextStyle {
        FontFamilyVariant(.monospaced)
        FontSize(.em(0.85))
      }
      .padding(16)
      .background(Color(.secondarySystemBackground))
      .clipShape(RoundedRectangle(cornerRadius: 6))
      .markdow…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NunoLemos101
Comment options

Answer selected by NunoLemos101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants