aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/utilities/Html.kt
blob: 4f34eab0089a291539a524ecdedb9b95c266f758 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package org.jetbrains.dokka.utilities

import org.jetbrains.dokka.InternalDokkaApi
import java.net.URLEncoder


/**
 * Replaces symbols reserved in HTML with their respective entities.
 * Replaces & with &amp;, < with &lt; and > with &gt;
 */
@InternalDokkaApi
fun String.htmlEscape(): String = replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;")

@InternalDokkaApi
fun String.urlEncoded(): String = URLEncoder.encode(this, "UTF-8")

@InternalDokkaApi
fun String.formatToEndWithHtml() =
    if (endsWith(".html") || contains(Regex("\\.html#"))) this else "$this.html"