<commit_before>//
//  CodeBlockModel.swift
//  Freetime
//
//  Created by <NAME> on 4/7/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import Foundation
import StyledTextKit

func CodeBlockElement(
    text: String,
    language: String?,
    contentSizeCategory: UIContentSizeCategory
    ) -> IssueCommentCodeBlockModel {
    let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)
    let attributedString: NSAttributedString

    let fixedLanguage = language?.isEmpty == true ? nil : language
    if let language = fixedLanguage,
        let highlighted = GithubHighlighting.highlight(trimmedText, as: language) {
        attributedString = highlighted
    } else {
        attributedString = NSAttributedString(
            string: trimmedText,
            attributes: [
                .foregroundColor: Styles.Colors.Gray.dark.color,
                .font: Styles.Text.code.font(contentSizeCategory:contentSizeCategory)
            ]
        )
    }

    var inset = IssueCommentCodeBlockCell.textViewInset
    inset.left += IssueCommentCodeBlockCell.scrollViewInset.left
    inset.right += IssueCommentCodeBlockCell.scrollViewInset.right

    let backgroundColor = Styles.Colors.Gray.lighter.color
    let builder = StyledTextBuilder(attributedText: attributedString)
        .add(attributes: [.backgroundColor: backgroundColor])
    let string = StyledTextRenderer(
        string: builder.build(),
        contentSizeCategory: contentSizeCategory,
        inset: inset,
        backgroundColor: backgroundColor
    )
    return IssueCommentCodeBlockModel(
        code: string,
        language: fixedLanguage
    )
}<commit_msg>warm code block caches (#2039)<commit_after>//
//  CodeBlockModel.swift
//  Freetime
//
//  Created by <NAME> on 4/7/18.
//  Copyright © 2018 <NAME>. All rights reserved.
//

import Foundation
import StyledTextKit

func CodeBlockElement(
    text: String,
    language: String?,
    contentSizeCategory: UIContentSizeCategory
    ) -> IssueCommentCodeBlockModel {
    let trimmedText = text.trimmingCharacters(in: .whitespacesAndNewlines)
    let attributedString: NSAttributedString

    let fixedLanguage = language?.isEmpty == true ? nil : language
    if let language = fixedLanguage,
        let highlighted = GithubHighlighting.highlight(trimmedText, as: language) {
        attributedString = highlighted
    } else {
        attributedString = NSAttributedString(
            string: trimmedText,
            attributes: [
                .foregroundColor: Styles.Colors.Gray.dark.color,
                .font: Styles.Text.code.font(contentSizeCategory:contentSizeCategory)
            ]
        )
    }

    var inset = IssueCommentCodeBlockCell.textViewInset
    inset.left += IssueCommentCodeBlockCell.scrollViewInset.left
    inset.right += IssueCommentCodeBlockCell.scrollViewInset.right

    let backgroundColor = Styles.Colors.Gray.lighter.color
    let builder = StyledTextBuilder(attributedText: attributedString)
        .add(attributes: [.backgroundColor: backgroundColor])
    let string = StyledTextRenderer(
        string: builder.build(),
        contentSizeCategory: contentSizeCategory,
        inset: inset,
        backgroundColor: backgroundColor
    ).warm(width: 0)
    return IssueCommentCodeBlockModel(
        code: string,
        language: fixedLanguage
    )
}
{'fraction_non_alphanumeric': 0.08358120166567519, 'fraction_numerical': 0.006246281975014872, 'mean_word_length': 2.9893238434163703, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6340891', 'n_tokens_mistral': 945, 'n_tokens_neox': 892, 'n_words': 198}