-
Notifications
You must be signed in to change notification settings - Fork 0
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
Переделать обработку красных строк #15
Comments
По идее, работающий вариант решения должен выглядеть примерно так (это не рабочий код, просто сама идея): #let indent = 1em
#let styled = [#set text(red)].func()
#let space = [ ].func()
#let sequence = [].func()
#let turn-on-first-line-indentation(
doc,
last-is-heading: false, // space and parbreak are ignored
indent-already-added: false,
) = {
if tyle(doc) == content {
for (i, elem) in doc.children.enumerate() {
turn-on-first-line-indentation(doc, last-is-heading: last-is-heading, indent-already-added: indent-already-added)
}
return
}
let element = elem.func()
if element == text {
let previous-elem = doc.children.at(i - 1)
if i == 0 or last-is-heading or previous-elem.func() == parbreak {
if not indent-already-added {
indent-already-added = true
h(indent)
}
}
elem
} else if element == heading {
indent-already-added = false
last-is-heading = true
elem
} else if element == space {
elem
} else if element == parbreak {
indent-already-added = false
elem
} else if element == sequence {
turn-on-first-line-indentation(
elem,
last-is-heading: last-is-heading,
indent-already-added: indent-already-added,
)
} else if element == styled {
styled(turn-on-first-line-indentation(
elem.child,
last-is-heading: last-is-heading,
indent-already-added: indent-already-added,
), elem.styles)
} else {
indent-already-added = false
last-is-heading = false
elem
}
}
#show: turn-on-first-line-indentation В таком случае мы заранее убедимся, что doc является content и пройдёмся циклом по его детям, а в противном случае будем считать, что мы уже работаем с детьми. Прежде чем что-то предпринимать, я бы дождался комментариев автора оригинального кода, потому что вперёд батьки в пекло переть не хочется, мне его авторитет не позволяет. |
Я думаю, это достаточно красноречивый ответ |
В злосчастном #13 (comment), конечно, было найдено временное решение с https://forum.typst.app/t/how-to-indent-every-paragraph-excluding-headings/2137/2, но меня очень напрягает необходимость дублировать один и тот же код, например, для заголовков и для таблиц. Было бы неплохо найти более надёжный вариант для неубирания красных строк.
The text was updated successfully, but these errors were encountered: