feat: count characters consistently

This commit is contained in:
Sam 2023-04-02 22:50:22 +02:00
parent 80ca1cae00
commit 8433a1523a
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
9 changed files with 54 additions and 20 deletions

View file

@ -6,6 +6,8 @@ const md = new MarkdownIt({
breaks: true,
}).disable(["heading", "link", "table"]);
export default function renderMarkdown(src: string | null) {
export function renderMarkdown(src: string | null) {
return src ? sanitize(md.render(src)) : null;
}
export const charCount = (str: string) => [...str].length;

View file

@ -30,7 +30,7 @@
import { apiFetchClient } from "$lib/api/fetch";
import ErrorAlert from "$lib/components/ErrorAlert.svelte";
import { goto } from "$app/navigation";
import renderMarkdown from "$lib/api/markdown";
import {renderMarkdown} from "$lib/utils"
import ReportButton from "./ReportButton.svelte";
import ProfileLink from "./ProfileLink.svelte";
import { memberNameRegex } from "$lib/api/regex";

View file

@ -9,7 +9,7 @@
import { memberAvatars, pronounDisplay, WordStatus } from "$lib/api/entities";
import { PUBLIC_BASE_URL } from "$env/static/public";
import { userStore } from "$lib/store";
import renderMarkdown from "$lib/api/markdown";
import { renderMarkdown } from "$lib/utils";
import ReportButton from "../ReportButton.svelte";
import ProfileLink from "../ProfileLink.svelte";
import StatusLine from "$lib/components/StatusLine.svelte";

View file

@ -38,7 +38,7 @@
import type { PageData } from "./$types";
import { addToast, delToast } from "$lib/toast";
import { memberNameRegex } from "$lib/api/regex";
import renderMarkdown from "$lib/api/markdown";
import { charCount, renderMarkdown } from "$lib/utils";
const MAX_AVATAR_BYTES = 1_000_000;
@ -445,7 +445,7 @@
<textarea class="form-control" style="height: 200px;" bind:value={bio} />
</div>
<p class="text-muted mt-1">
Using {bio.length}/{MAX_DESCRIPTION_LENGTH} characters
Using {charCount(bio)}/{MAX_DESCRIPTION_LENGTH} characters
</p>
<p class="text-muted my-2">
<Icon name="info-circle-fill" aria-hidden /> Your bio supports limited

View file

@ -34,7 +34,7 @@
import ErrorAlert from "$lib/components/ErrorAlert.svelte";
import { addToast, delToast } from "$lib/toast";
import type { PageData } from "./$types";
import renderMarkdown from "$lib/api/markdown";
import { charCount, renderMarkdown } from "$lib/utils";
const MAX_AVATAR_BYTES = 1_000_000;
@ -373,7 +373,7 @@
<textarea class="form-control" style="height: 200px;" bind:value={bio} />
</div>
<p class="text-muted mt-1">
Using {bio.length}/{MAX_DESCRIPTION_LENGTH} characters
Using {charCount(bio)}/{MAX_DESCRIPTION_LENGTH} characters
</p>
<p class="text-muted my-2">
<Icon name="info-circle-fill" aria-hidden /> Your bio supports limited