New FAMILUG

The PyMiers

Showing posts with label ipdb. Show all posts
Showing posts with label ipdb. Show all posts

Monday, 24 February 2014

[Python] docutils package (hay nhật ký tìm hiểu 1 python package)

Bài viết này dành cho những ai biết các khái niệm pip, virtualenv, package/module trong python. Hoặc những ai muốn xem ví dụ sử dụng một số câu lệnh để khám phá 1 directory.

Docutils is a modular system for processing documentation into useful formats, such as HTML, XML, and LaTeX. For input Docutils supports reStructuredText, an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax.

Tóm lại module (hay package) này thực hiện các công việc giúp đọc 1 file .rst (reStructuredText) và cho phép xuất ra các output khác nhau (HTML, XML, LaTeX)

Ví dụ:
 rst2html.py monitor.rst out.html
Document của docutils khá là sơ sài, có mỗi page này có vẻ có chút thông tin:
http://docutils.sourceforge.net/docs/dev/hacking.html


Các bước hoạt động

docutils chuyển đổi 1 file .rst sang .html qua 4 giai đoạn:
1. Reader : đọc document từ source file và chuyển cho Parser
2. Parser: phân tích document nhận được, tạo 1node tree document.
3. Transform: thực hiện tranform ví dụ như biến 1 reference thành 1 link cụ thể.
4. Writer: nhận node tree sau khi transform và thực hiện ghi ra file đích.

Introspect docutils (soi và ngắm)