GithubHelp home page GithubHelp logo

sereneinserenade / tiptap-languagetool Goto Github PK

View Code? Open in Web Editor NEW
103.0 3.0 15.0 374 KB

Tiptap-Extension to integrate LanguageTool to Tiptap 2.

Home Page: https://tiptap-languagetool.vercel.app/

License: MIT License

HTML 1.85% Vue 16.30% TypeScript 79.93% JavaScript 1.92%
languagetool languagetool-server tiptap tiptap-v2 typescript vue vue3

tiptap-languagetool's Introduction

tiptap-languagetool

Extension for integrating Languagetool with TipTap. You can have your self-hosted instance of LanguageTool, details for that are here.

A โญ๏ธ to the repo if you ๐Ÿ‘ / โค๏ธ what I'm doing would be much appreciated. If you're using this extension and making money from it, it'd be very kind of you to โค๏ธ Sponsor me. If you're looking for a dev to work you on your project's Rich Text Editor with or as **a frontend developer, DM me on Discord/Twitter/LinkedIn๐Ÿ‘จโ€๐Ÿ’ป๐Ÿคฉ.

I've made a bunch of extensions for Tiptap 2, some of them are Google Docs like Commenting, Search and Replace, Resizable Images and Videos with tiptap. You can check it our here https://github.com/sereneinserenade#a-glance-of-my-projects.

Special thanks to @rezaffm for sponsoring this project.

Live Demo

You can try out live-demo with mocked data at https://tiptap-languagetool.vercel.app/ or look at the demo-video below. The code for demo is in mocked-demo branch.

Demo Video
language-tool.mp4

How to use

Copy the languagetool.ts or languagetool.js file in your project depending on whether you use TypeScript or not. Then import the extension from that file and give it to the TipTap.

import { LanguageTool, Match } from './extensions/languagetool'

const match = ref<Match>(null)

const updateMatch = (editor: Editor) => match.value = editor.extensionStorage.languagetool.match

const replacements = computed(() => match.value?.replacements || [])

const matchMessage = computed(() => match.value?.message || 'No Message')

const updateHtml = () => navigator.clipboard.writeText(editor.value.getHTML())

const acceptSuggestion = (sug) => {
  editor.value.commands.insertContent(sug.value)
}

const proofread = () => editor.value.commands.proofread()

const editor = useEditor({
  content,
  extensions: [StarterKit, LanguageTool.configure({ 
    language: 'auto', // it can detect language automatically or you can write your own language like 'en-US'
    apiUrl: YOUR_LANGUAGETOOL_SERVER_URL_HERE + 'check', // For testing purposes, you can use [Public API](https://dev.languagetool.org/public-http-api), but keep an eye on the rules that they've written there
    automaticMode: true, // if true, it will start proofreading immediately otherwise only when you execute `proofread` command of the extension.
  })],
  onUpdate({ editor }) {
    setTimeout(() => updateMatch(editor as any))
  },
  onSelectionUpdate({ editor }) {
    setTimeout(() => updateMatch(editor as any))
  },
})

Now showing the suggestion on click, so now in the vue component where you've implemented tiptap.

<bubble-menu
  class="bubble-menu"
  v-if="editor"
  :editor="editor"
  :tippy-options="{ placement: 'bottom', animation: 'fade' }"
>
  <section class="bubble-menu-section-container">
    <section class="message-section">
      {{ matchMessage }}
    </section>
    <section class="suggestions-section">
      <article
        v-for="(replacement, i) in replacements"
        @click="() => acceptSuggestion(replacement)"
        :key="i + replacement.value"
        class="suggestion"
      >
        {{ replacement.value }}
      </article>
    </section>
  </section>
</bubble-menu>

You can implement your own styles or copy the ones in Tiptap.vue.

Stargazers

Stargazers repo roster for @sereneinserenade/tiptap-languagetool


Project Setup(Stuff that nobody really cares about)
npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Lints and fixes files

npm run lint

Customize configuration

See Configuration Reference.

tiptap-languagetool's People

Contributors

aiyush-g avatar escapedcat avatar sereneinserenade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tiptap-languagetool's Issues

Rich editor (bold, italic and other inner nodes) spellcheck bug

Hey mate! Thanks for the plugin. Currently, I'm refactoring it for my internal needs, I don't want any side effects to be handled inside the plugin. It seems like there is a bug in the algorithm:

if you mark a selection with bold (or any other), it will mark the next word as a misspelling. As in the case below, it thinks that the next word always should start with a capital letter. I think (and to be honest I didn't have any time to investigate yet), the problem is that you are trying to check not the entire block, but just part of it. Would really appreciate some help here:

Screenshot 2022-05-20 at 21 20 06

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.