Giter Site home page Giter Site logo

policystat / docx2html Goto Github PK

View Code? Open in Web Editor NEW
41.0 9.0 14.0 833 KB

Convert a docx (OOXML) file to html. This project is deprecated in favor of https://github.com/OpenScienceFramework/pydocx

License: BSD 3-Clause "New" or "Revised" License

Python 99.91% Shell 0.09%

docx2html's Introduction

========= docx2html

Convert a docx (OOXML) file to semantic HTML. All of Word formatting nonsense is stripped away and you're left with a cleanly-formatted version of the content.

Usage

>>> from docx2html import convert
>>> html = convert('path/to/docx/file')

Running Tests for Development

::

 $ virtualenv path/to/new/virtualenv
 $ source path/to/new/virtualenv/bin/activate
 $ cd path/to/workspace
 $ git clone git://github.com/PolicyStat/docx2html.git
 $ cd docx2html
 $ pip install .
 $ pip install -r test_requirements.txt
 $ ./run_tests.sh

Description

docx2html is designed to take a docx file and extract the content out and convert that content to html. It does not care about styles or fonts or anything that changes how the content is displayed (with few exceptions). Below is a list of what currently works:

  • Paragraphs
    • Bold
    • Italics
    • Underline
    • Hyperlinks
  • Lists
    • Nested lists
    • List styles (letters, roman numerals, etc.)
    • Tables
    • Paragraphs
  • Tables
    • Rowspans
    • Colspans
    • Nested tables
    • Lists
  • Images
    • Resizing
    • Converting to smaller formats (for bitmaps and tiffs)
    • There is a hook to allow setting the src of the image tag out of context, more on this later
  • Headings
    • Simple headings
    • Root level lists that are upper case roman numerals get converted to h2 tags

Handling embedded images

docx2html allows you to specify how you would like to handle image uploading. For example, you might be uploading your images to Amazon S3 eg: Note: This documentation sucks, so you might need to read the source.

::

import os.path
from shutil import copyfile

from docx2html import convert

def handle_image(image_id, relationship_dict):
    image_path = relationship_dict[image_id]
    # Now do something to the image. Let's move it somewhere.
    _, filename = os.path.split(image_path)
    destination_path = os.path.join('/tmp', filename)
    copyfile(image_path, destination_path)

    # Return the `src` attribute to be used in the img tag
    return 'file://%s' % destination

html = convert('path/to/docx/file', image_handler=handle_image)

Naming Conventions

There are two main naming conventions in the source for docx2html there are build functions, which will return an etree element that represents HTML. And there are get_content functions which return string representations of HTML.

docx2html's People

Contributors

jlward avatar winhamwr 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.