Skip to content

Commit

Permalink
iOS: Fix "undefined" values in fill blanks problem because the highli…
Browse files Browse the repository at this point in the history
…ght language is not supported (#1139)

^ALTAPPS-1189
  • Loading branch information
ivan-magda authored Aug 1, 2024
1 parent bd8fb30 commit 5921753
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum CodeLanguage: String, CaseIterable {
case pascal = "pascalabc"
case perl = "perl"
case sql = "sql"
case mysql = "mysql"
case swift = "swift"
case php = "php"
case julia = "julia"
Expand Down Expand Up @@ -78,7 +79,7 @@ enum CodeLanguage: String, CaseIterable {
return "delphi"
case .perl:
return "perl"
case .sql:
case .sql, .mysql:
return "sql"
case .swift:
return "swift"
Expand Down Expand Up @@ -133,6 +134,8 @@ enum CodeLanguage: String, CaseIterable {
return "Perl"
case .sql:
return "SQL"
case .mysql:
return "MySQL"
case .swift:
return "Swift"
case .php:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ enum CodeLanguageSamples {
return pascal
case .perl:
return perl
case .sql:
case .sql, .mysql:
return sql
case .swift:
return swift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ final class StepQuizFillBlanksViewDataMapper {

private func mapFillBlanksDataToViewData(_ fillBlanksData: FillBlanksData) -> StepQuizFillBlanksViewData {
let language = fillBlanksData.language
let codeLanguage = language.flatMap(CodeLanguage.init(rawValue:))

var components = fillBlanksData.fillBlanks
.map { mapFillBlanksItem($0, language: language) }
.map { mapFillBlanksItem($0, language: language, codeLanguage: codeLanguage) }
.flatMap { $0 }
for index in components.indices {
components[index].id = index
Expand All @@ -63,7 +64,8 @@ final class StepQuizFillBlanksViewDataMapper {

private func mapFillBlanksItem(
_ fillBlanksItem: FillBlanksItem,
language: String?
language: String?,
codeLanguage: CodeLanguage?
) -> [StepQuizFillBlankComponent] {
switch FillBlanksItemKs(fillBlanksItem) {
case .text(let data):
Expand All @@ -80,7 +82,7 @@ final class StepQuizFillBlanksViewDataMapper {
} else {
let unescaped = HTMLString.unescape(string: data.text)

if let highlightedCode = highlight(code: unescaped, language: language) {
if let highlightedCode = highlight(code: unescaped, codeLanguage: codeLanguage) {
cache.setHighlightedCode(highlightedCode, for: hash)
result.append(StepQuizFillBlankComponent(type: .text, attributedText: highlightedCode))
} else {
Expand All @@ -101,7 +103,7 @@ final class StepQuizFillBlanksViewDataMapper {
}
}

private func highlight(code: String, language: String?) -> NSAttributedString? {
highlightr.highlight(code, as: language, fastRender: true)
private func highlight(code: String, codeLanguage: CodeLanguage?) -> NSAttributedString? {
highlightr.highlight(code, as: codeLanguage?.highlightr, fastRender: true)
}
}

0 comments on commit 5921753

Please sign in to comment.