Skip to content
GitHub

Bold

The bold mark is used to represent text that is using a bold font weight. It will be rendered as <strong> element in HTML.

<script setup lang="ts">
import 'prosekit/basic/style.css'

import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/vue'
import {
  ref,
  watchPostEffect,
} from 'vue'

import { defineExtension } from './extension'
import Toolbar from './toolbar.vue'

const defaultContent = `
  <p><b>This is bold</b></p>
  <p><strong>This is bold too</strong></p>
  <p><span>This is normal text</span></p>
`

const editor = createEditor({ extension: defineExtension(), defaultContent })
const editorRef = ref<HTMLDivElement | null>(null)
watchPostEffect((onCleanup) => {
  editor.mount(editorRef.value)
  onCleanup(() => editor.unmount())
})
</script>

<template>
  <ProseKit :editor="editor">
    <div class='box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 shadow dark:border-zinc-700 flex flex-col bg-white dark:bg-gray-950'>
      <Toolbar />
      <div class='relative w-full flex-1 box-border overflow-y-scroll'>
        <div ref="editorRef" class='ProseMirror box-border min-h-full px-[max(4rem,_calc(50%-20rem))] py-8 outline-none outline-0 [&_span[data-mention="user"]]:text-blue-500 [&_span[data-mention="tag"]]:text-violet-500' />
      </div>
    </div>
  </ProseKit>
</template>

Commands

toggleBold

import { createEditor } from 'prosekit/core'
import { defineBold } from 'prosekit/extensions/bold'

const extension = defineBold()
const editor = createEditor({ extension })

// ---cut---
editor.commands.toggleBold()

Keyboard Shortcuts

Non-AppleAppleDescription
Ctrl-BCommand-BToggle the current selection to bold

API Reference