Giter Club home page Giter Club logo

wikitext-table-parser's Introduction

Wikitext Table Parser

A Rust implement for parse the wikitext's table.

What is this project for ?

The wikitext is a special format used by wikipedia, most available wiki data or processing tool ignore the table data. This project implement a wikitext-table parser that help one to processing the table in wikitext or wiki-dump.

A table in wikitext should like:

{| class="wikitable"
|+ Caption text
|-
! Header text !! Header text !! Header text
|-
| Example || Example || Example
|-
| Example || Example || Example
|-
| Example || Example || Example
|}

also see the reference of wikitext table for more detail.

Usage Example

use std::fs::File;
use std::io::Read;
use std::env;
use wikitext_table_parser::parser::{Event as ParserEvent, WikitextTableParser};

fn main() {
    let args: Vec<String> = env::args().collect();
    let file_path = args[1].clone();

    // Attempt to open the file
    let mut file = match File::open(file_path) {
        Ok(file) => file,
        Err(_) => {
            eprintln!("Error opening the file.");
            return;
        }
    };

    // Read the contents of the file into a String
    let mut content = String::new();
    if let Err(_) = file.read_to_string(&mut content) {
        eprintln!("Error reading the file into a string.");
        return;
    }

    let wikitext_table_parser = WikitextTableParser::new(&content);
    for event in wikitext_table_parser {
        match event {
            ParserEvent::TableStart => {
                println!("Table START!");
            }
            ParserEvent::TableStyle(table_style) => {
                println!("table style{:?}#", table_style);
            }
            ParserEvent::TableTitle(text) => {
                println!("table name{:?}#", text);
            }
            ParserEvent::Row(row_style) => {
                println!("----- {:?} -----", row_style);
            }
            ParserEvent::ColStyle(col_style) => {
                print!("col style: {:?}# ", col_style);
            }
            ParserEvent::Col(text) => {
                println!("col: {:?}#", text);
            }
            ParserEvent::TableEnd => {
                println!("Table END!");
            }
            _ => {}
        }
    }
}

wikitext-table-parser's People

Contributors

p208p2002 avatar

Watchers

 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.