Hướng dẫn rtf to html open source - rtf sang mã nguồn mở html

Tên đã được sử dụng

Một thẻ đã tồn tại với tên chi nhánh được cung cấp. Nhiều lệnh GIT chấp nhận cả tên thẻ và tên chi nhánh, vì vậy việc tạo nhánh này có thể gây ra hành vi bất ngờ. Bạn có chắc là bạn muốn tạo chi nhánh này?

1branch2tags branch 2 tags

Mã số

  • Sử dụng Git hoặc thanh toán với SVN bằng URL Web.

  • Mở bằng máy tính để bàn GitHub
  • Tải xuống Zip

Cam kết mới nhất

Các tập tin

Permalink

Không tải thông tin cam kết mới nhất.

Loại hình

Tên

Tin nhắn cam kết mới nhất

Cam kết thời gian

rtf-to-html

RTF tuân thủ RFC duy nhất trên thế giới cho trình phân tích cú pháp HTML.

RTF-to-HTML có sẵn ở Maven Central:


    com.github.bbottema
    rtf-to-html
    1.0.0

Cách sử dụng

Có ba phiên bản RTF đến HTML để bạn khám phá:three versions of RTF to HTML for you to discover:

  • Rtf2htmlconverterjeditorpane: một bộ chuyển đổi gọi hỗ trợ RTF gốc của Swing
  • RTF2HTMLConverterClassic: Bộ chuyển đổi được chế tạo tùy chỉnh [dựa trên regex] với kết quả hợp lý
  • RTF2HTMLConverterJeditorPane: Trình phân tích cú pháp tuân thủ RFC được cải tiến với kết quả chính xác nhất

RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;

String html = converter.rtf2html["RTF text"];

Tiến trình mới nhất

v1.0.1 [22 tháng 10-2019]

  • #1: Thiếu hỗ trợ cho tên di sản của UTF-8 [CP] 65001

v1.0.0 [12 tháng 10-2019]

  • Phát hành ban đầu, chuyển từ Outlook-Message-Parser

@iarna/rtf-to-html

DOC - Một tài liệu RTF được phân tích cú pháp được sản xuất bởi thư viện rtf-parser.

const rtfToHTML = require['@iarna/rtf-to-html']

fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
  // …
}]
rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
  // …
}]
rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
  console.log[html]
  // prints a document containing:
  // 

hi there

}]

OPTS - Tùy chọn tùy chọn, xem phần về các tùy chọn để biết chi tiết.

Chuyển đổi RTF thành HTML trong JavaScript thuần túy.

Điều này được xây dựng trên rtf-parser và chia sẻ những hạn chế của nó.

  • Điều này tạo ra các tài liệu HTML hoàn chỉnh từ các tài liệu RTF. Nó hiện không có cơ sở để làm việc trên các đoạn trích của.
  • Các tính năng được hỗ trợ:
    • Phát hiện đoạn văn [kết quả trong thẻ

      ] cộng với việc cắt đoạn đoạn trống.

    • Phông chữ [như font-family: Font Name, Font Family]. Các gia đình phông chữ trong RTF không ánh xạ hoàn hảo với HTML. Đây là bản đồ chúng tôi hiện đang sử dụng:
    • La Mã: Serif
    • Thụy Sĩ: Sans-serif
    • Kịch bản: chữ thảo
    • Trang trí: tưởng tượng
    • Hiện đại: Sans-serif
  • Tech: Monospace
  • Bidi: Serif
  • Kích thước phông chữ [như font-size: #pt]
  • In đậm [như ]
  • In nghiêng [như ]
  • Gạch chân [như ____10]
  • Strikethrough [như
    RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;
    
    String html = converter.rtf2html["RTF text"];
    1]
  • SuperScript [như
    RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;
    
    String html = converter.rtf2html["RTF text"];
    2]
  • Chỉ số [như
    RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;
    
    String html = converter.rtf2html["RTF text"];
    3]
  • Màu tiền cảnh [như
    RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;
    
    String html = converter.rtf2html["RTF text"];
    4]
  • Màu nền [như
    RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;
    
    String html = converter.rtf2html["RTF text"];
    4]
  • Đoạn văn đầu tiên [như
    RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;
    
    String html = converter.rtf2html["RTF text"];
    6]

Các vùng được xác định [là
RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;

String html = converter.rtf2html["RTF text"];
7]

  • OPTS - Tùy chọn tùy chọn để chuyển đến Trình tạo HTML. Xem phần về các tùy chọn để biết chi tiết.
  • CB - Một cuộc gọi lại chấp nhận
    RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;
    
    String html = converter.rtf2html["RTF text"];
    9, xem phần trên cuộc gọi lại để biết chi tiết.

Trả về một WritableStream mà bạn có thể đi vào.

rtftohtml.fromStream [Stream [, opts], cb]

  • Luồng - Một luồng có thể đọc được có chứa RTF.
  • OPTS - Tùy chọn tùy chọn để chuyển đến Trình tạo HTML. Xem phần về các tùy chọn để biết chi tiết.
  • CB - Một cuộc gọi lại chấp nhận
    RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;
    
    String html = converter.rtf2html["RTF text"];
    9, xem phần trên cuộc gọi lại để biết chi tiết.

rtftohtml.fromString [chuỗi [, opts], cb]

  • Chuỗi - Một chuỗi chứa RTF.
  • OPTS - Tùy chọn tùy chọn để chuyển đến Trình tạo HTML. Xem phần về các tùy chọn để biết chi tiết.
  • CB - Một cuộc gọi lại chấp nhận
    RTF2HTMLConverter converter = RTF2HTMLConverterJEditorPane.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterClassic.INSTANCE;
    RTF2HTMLConverter converter = RTF2HTMLConverterRFCCompliant.INSTANCE;
    
    String html = converter.rtf2html["RTF text"];
    9, xem phần trên cuộc gọi lại để biết chi tiết.

rtftohtml.fromString [chuỗi [, opts], cb]

Chuỗi - Một chuỗi chứa RTF.

Gọi lại

RTFTOHTML trả về HTML được sản xuất từ ​​RTF bằng cách sử dụng gọi lại kiểu Node.js tiêu chuẩn, sẽ chấp nhận các đối số sau: `[err, html]`.

Nếu chúng ta gặp phải lỗi trong phân tích cú pháp thì nó sẽ được đặt trong
const rtfToHTML = require['@iarna/rtf-to-html']

fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
  // …
}]
rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
  // …
}]
rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
  console.log[html]
  // prints a document containing:
  // 

hi there

}]
2. Nếu không, HTML kết quả sẽ có trong
const rtfToHTML = require['@iarna/rtf-to-html']

fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
  // …
}]
rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
  // …
}]
rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
  console.log[html]
  // prints a document containing:
  // 

hi there

}]
3.
  • Tùy chọn
  • paratag - [mặc định là
    const rtfToHTML = require['@iarna/rtf-to-html']
    
    fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
      // …
    }]
    rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
      // …
    }]
    rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
      console.log[html]
      // prints a document containing:
      // 

    hi there

    }]
    5] TagName để sử dụng cho các đoạn văn.
  • Mẫu - một hàm được sử dụng để tạo tài liệu HTML cuối cùng, mặc định là:

    function outputTemplate [doc, defaults, content] {
      return `
    
      
        
        
        body {
          margin-left: ${doc.marginLeft / 20}pt;
          margin-right: ${doc.marginRight / 20}pt;
          margin-top: ${doc.marginTop / 20}pt;
          margin-bottom: ${doc.marginBottom / 20}pt;
          font-size: ${defaults.fontSize / 2}pt;
          text-indent: ${defaults.firstLineIndent / 20}pt;
        }
        
      
      
        ${content.replace[/\n/, '\n    ']}
      
    `
    }

Bạn cũng có thể định cấu hình một số trạng thái bắt đầu [mặc định] của định dạng đầu ra với:

  • Vô hiệu hóa - mặc định là
    const rtfToHTML = require['@iarna/rtf-to-html']
    
    fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
      // …
    }]
    rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
      // …
    }]
    rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
      console.log[html]
      // prints a document containing:
      // 

    hi there

    }]
    6. Nếu bạn đặt điều này thành
    const rtfToHTML = require['@iarna/rtf-to-html']
    
    fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
      // …
    }]
    rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
      // …
    }]
    rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
      console.log[html]
      // prints a document containing:
      // 

    hi there

    }]
    7 thì chúng tôi sẽ xuất hiện thông tin thay đổi phông chữ khi chúng tôi gặp phải. Đây là một chút bị phá vỡ do các kiểu không hỗ trợ của chúng tôi.
  • Phông chữ - Mặc định cho kích thước phông chữ được khai báo trên toàn tài liệu hoặc nếu thiếu,
    const rtfToHTML = require['@iarna/rtf-to-html']
    
    fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
      // …
    }]
    rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
      // …
    }]
    rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
      console.log[html]
      // prints a document containing:
      // 

    hi there

    }]
    8.
  • in đậm - mặc định là
    const rtfToHTML = require['@iarna/rtf-to-html']
    
    fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
      // …
    }]
    rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
      // …
    }]
    rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
      console.log[html]
      // prints a document containing:
      // 

    hi there

    }]
    7
  • Italic - mặc định là
    const rtfToHTML = require['@iarna/rtf-to-html']
    
    fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
      // …
    }]
    rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
      // …
    }]
    rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
      console.log[html]
      // prints a document containing:
      // 

    hi there

    }]
    7
  • Underline - Mặc định là
    const rtfToHTML = require['@iarna/rtf-to-html']
    
    fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
      // …
    }]
    rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
      // …
    }]
    rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
      console.log[html]
      // prints a document containing:
      // 

    hi there

    }]
    7
  • Strikethrough - Mặc định là
    const rtfToHTML = require['@iarna/rtf-to-html']
    
    fs.createReadStream['example.rtf'].pipe[rtfToHTML[[err, html] => {
      // …
    }]
    rtfToHTML.fromStream[fs.createReadStream['example.rtf'], [err, html] => {
      // …
    }]
    rtfToHTML.fromString['{\\rtf1\\ansi\\b hi there\\b0}', [err, html] => {
      console.log[html]
      // prints a document containing:
      // 

    hi there

    }]
    7
  • Tiền cảnh - Mặc định là
    function outputTemplate [doc, defaults, content] {
      return `
    
      
        
        
        body {
          margin-left: ${doc.marginLeft / 20}pt;
          margin-right: ${doc.marginRight / 20}pt;
          margin-top: ${doc.marginTop / 20}pt;
          margin-bottom: ${doc.marginBottom / 20}pt;
          font-size: ${defaults.fontSize / 2}pt;
          text-indent: ${defaults.firstLineIndent / 20}pt;
        }
        
      
      
        ${content.replace[/\n/, '\n    ']}
      
    `
    }
    3
  • Bối cảnh - Mặc định là
    function outputTemplate [doc, defaults, content] {
      return `
    
      
        
        
        body {
          margin-left: ${doc.marginLeft / 20}pt;
          margin-right: ${doc.marginRight / 20}pt;
          margin-top: ${doc.marginTop / 20}pt;
          margin-bottom: ${doc.marginBottom / 20}pt;
          font-size: ${defaults.fontSize / 2}pt;
          text-indent: ${defaults.firstLineIndent / 20}pt;
        }
        
      
      
        ${content.replace[/\n/, '\n    ']}
      
    `
    }
    4
  • FirstLineIndent - Mặc định với giá trị toàn tài liệu hoặc nếu bị thiếu,
    function outputTemplate [doc, defaults, content] {
      return `
    
      
        
        
        body {
          margin-left: ${doc.marginLeft / 20}pt;
          margin-right: ${doc.marginRight / 20}pt;
          margin-top: ${doc.marginTop / 20}pt;
          margin-bottom: ${doc.marginBottom / 20}pt;
          font-size: ${defaults.fontSize / 2}pt;
          text-indent: ${defaults.firstLineIndent / 20}pt;
        }
        
      
      
        ${content.replace[/\n/, '\n    ']}
      
    `
    }
    5. Đây là bao xa để thụt dòng dòng đầu tiên của các đoạn mới.
  • thụt lề: mặc định là
    function outputTemplate [doc, defaults, content] {
      return `
    
      
        
        
        body {
          margin-left: ${doc.marginLeft / 20}pt;
          margin-right: ${doc.marginRight / 20}pt;
          margin-top: ${doc.marginTop / 20}pt;
          margin-bottom: ${doc.marginBottom / 20}pt;
          font-size: ${defaults.fontSize / 2}pt;
          text-indent: ${defaults.firstLineIndent / 20}pt;
        }
        
      
      
        ${content.replace[/\n/, '\n    ']}
      
    `
    }
    5
  • Căn chỉnh: Mặc định là
    function outputTemplate [doc, defaults, content] {
      return `
    
      
        
        
        body {
          margin-left: ${doc.marginLeft / 20}pt;
          margin-right: ${doc.marginRight / 20}pt;
          margin-top: ${doc.marginTop / 20}pt;
          margin-bottom: ${doc.marginBottom / 20}pt;
          font-size: ${defaults.fontSize / 2}pt;
          text-indent: ${defaults.firstLineIndent / 20}pt;
        }
        
      
      
        ${content.replace[/\n/, '\n    ']}
      
    `
    }
    7.
  • Valign: Mặc định là
    function outputTemplate [doc, defaults, content] {
      return `
    
      
        
        
        body {
          margin-left: ${doc.marginLeft / 20}pt;
          margin-right: ${doc.marginRight / 20}pt;
          margin-top: ${doc.marginTop / 20}pt;
          margin-bottom: ${doc.marginBottom / 20}pt;
          font-size: ${defaults.fontSize / 2}pt;
          text-indent: ${defaults.firstLineIndent / 20}pt;
        }
        
      
      
        ${content.replace[/\n/, '\n    ']}
      
    `
    }
    8

const rtftohtml = yêu cầu ['rtf-to-html/rtf-to-html.js']]

rtftohtml [doc [, opts]] → html

Đây là nội bộ cách các giao diện khác được thực hiện. Không giống như các giao diện khác, cái này là đồng bộ.

  • DOC - Một tài liệu RTF được phân tích cú pháp được sản xuất bởi thư viện rtf-parser.
  • OPTS - Tùy chọn tùy chọn, xem phần về các tùy chọn để biết chi tiết.

Bài Viết Liên Quan

Chủ Đề