Coder Social home page Coder Social logo

pwli0755 / docx-annotation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nusr/docx-annotation

0.0 1.0 0.0 1.79 MB

It's a vue component that will convert docx to html and annotate html

Home Page: https://nusr.github.io/docx-annotation/

License: MIT License

JavaScript 97.30% Vue 0.92% CSS 1.67% Shell 0.11%

docx-annotation's Introduction

Downloads Version License

docx-annotation

It's a vue component that will convert docx to HTML an annotate HTML.

docx 文件转换为 HTML,以及 HTML 的在线批注功能。

Features

  1. javaScript convert docx to HTML
  2. annotate HTML online
  3. restore annotations from request

How to use ?

npm install --save docx-annotation

dependencies

  1. jQuery
  2. mammoth
  3. rangy

online demo

online demo

custom rangy library

Highlighter.prototype = {
  /**
   * restore selected text
   * @param {Object} item
   * @param {Object} applier
   * @param {String} containerElementId
   */
  addHighlight: function(item, applier, containerElementId) {
    var characterRange = new CharacterRange(+item.start, +item.end)
    var highlight = new Highlight(
      this.doc,
      characterRange,
      applier,
      this.converter,
      item.id,
      containerElementId
    )
    highlight.apply()
    this.highlights.push(highlight)
    return highlight
  }
}

request file example

<template>
  <docx-annotation @convert-start="convertStart" @convert-end="convertEnd" v-model="requestList" ref="annotationRequest" />
</template>
<script>
  export default {
    data(){
      return {
        requestList:[]
      }
    },
    mounted() {
      axios({ method: "get", url: filePath, responseType: "arraybuffer" }).then(
        ({ data }) => {
          this.$refs.annotationRequest.wordToHtml(data)
        }
      )
    },
    methods:{
       convertStart(){
          console.log('convert-start')
        },
        convertEnd(){
          console.log('convert-end')
        }
    }
  }
</script>

advanced example

<template>
  <docx-annotation
    @convert-start="convertStart" @convert-end="convertEnd" v-model="advancedList"
    :click-scroll="true"
    ref="annotationAdvanced"
  />
</template>
<script>
  export default {
    data(){
      return {
        advancedList:[]
      }
    },
    mounted() {
      axios({ method: "get", url: filePath, responseType: "arraybuffer" }).then(
        ({ data }) => {
          this.$refs.annotationRequest.wordToHtml(data)
        }
      )
    },
    methods:{
       convertStart(){
          console.log('convert-start')
        },
        convertEnd(){
          console.log('convert-end')
        }
    }
  }
</script>

input file example

<template>
  <docx-annotation @convert-start="convertStart" @convert-end="convertEnd" v-model="inputList" ref="annotationInput" />
</template>
<script>
  export default {
    data(){
      return {
        inputList:[]
      }
    },
    mounted() {
      let _this = this
      $("#input-file-container").bind("change", function(event) {
        let file = event.target.files[0]
        let reader = new FileReader()
        reader.onload = function(loadEvent) {
          let arrayBuffer = loadEvent.target.result
          _this.$refs.annotationInput.wordToHtml(arrayBuffer)
        }
        reader.readAsArrayBuffer(file)
      })
    },
    methods:{
       convertStart(){
          console.log('convert-start')
        },
        convertEnd(){
          console.log('convert-end')
        }
    }
  }
</script>

Options

Property Description type default
value comment list Array []
clickScroll scroll to docx content Boolean false

Event Description
convert-start start convert docx to HTML
convert-end convert end

docx-annotation's People

Contributors

nusr avatar

Watchers

James Cloos avatar

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.