Giter Site home page Giter Site logo

dedalozzo / converter Goto Github PK

View Code? Open in Web Editor NEW
26.0 5.0 9.0 73 KB

A set of classes to translate a text from a HTML to BBcode and from BBCode to Markdown.

License: Apache License 2.0

PHP 100.00%
converter html bbcode markdown html-to-markdown html-to-bbcode bbcode-to-markdown php

converter's Introduction

Latest Stable Version Latest Unstable Version Build Status Scrutinizer Code Quality License Total Downloads

Converter

A set of classes to translate a text from HTML to BBCode and from BBCode to Markdown.

The HTML to BBCode converter, in particular, has not been created with the intent to convert an entire HTML page, but just to convert a set of HTML tags used to format articles and blog posts in the HTML era, when Markdown and BBcode didn't exist at all.

The special BBCode to Markdown converter is able to convert: bold, italic, underline and strikethrough texts, lists, urls, images, quotes and even code blocks (snippets).

Composer Installation

To install Converter, you first need to install Composer, a Package Manager for PHP, following these few steps:

curl -s https://getcomposer.org/installer | php

You can run this command to easily access composer from anywhere on your system:

sudo mv composer.phar /usr/local/bin/composer

Converter Installation

Once you have installed Composer, it's easy install Converter.

  1. Edit your composer.json file, adding Converter to the require section:
{
    "require": {
        "3f/converter": "dev-master"
    },
}
  1. Run the following command in your project root dir:
composer update

Usage

There are two classes: HTMLConverter and BBCodeConverter. The first class may be used to convert from HTML to BBCode, while the second one is used to convert from BBCode to Markdown.

HTML to BBCode conversion:

$converter = new Converter\HTMLConverter($text, $id);
echo $converter->toBBCode();

BBCode to Markdown conversion:

$converter = new Converter\BBCodeConverter($text, $id);
echo $converter->toMarkdown();

In both cases the $id is optional. When provided is used in case an exception is raised during the conversion process.

Documentation

The documentation can be generated using Doxygen. A Doxyfile is provided for your convenience.

Requirements

  • PHP 5.4.0 or above.

Authors

Filippo F. Fadda - [email protected] - http://www.linkedin.com/in/filippofadda

License

Converter is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

converter's People

Contributors

chellem avatar dedalozzo avatar mhatma avatar roni-estein 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

Watchers

 avatar  avatar  avatar  avatar  avatar

converter's Issues

How to include converter?

Hello
I am new to php namespaces and classes
I try to include your files like this

folder bb-converter
files
BBCodeConverter.php
HTMLConverter.php
Converter.php

index.php

<?php
namespace Converter;
include(dirname(__FILE__).'/BBCodeConverter.php');
include(dirname(__FILE__).'/HTMLConverter.php');
include(dirname(__FILE__).'/Converter.php');

//include(dirname(__FILE__).'/Converter/BBCodeConverter.php');
//include(dirname(__FILE__).'/Converter/HTMLConverter.php');
//include(dirname(__FILE__).'/Converter/Converter.php');

#HTML to BBCode conversion:
$id = 1;
$text = '<b>Bold</b>';
//$converter = new Converter\HTMLConverter($text, $id);
$converter = new HTMLConverter($text, $id);
echo $converter->toBBCode();

when i try
http://127.0.0.1/bb-converter/

I got this fatal error

Fatal error: Class 'Converter\Converter' not found in C:\xampp\htdocs\bb-converter\BBCodeConverter.php on line 16

Sorry for this newbie question,
can you advice how to proper include your converter.

Thank you

URLs to lower?

Why are all images converted to lower case?

The case "can" matter, so why force to lower?

Expand classes

Thanks for this little converter. It's simple and does the job.

It'd be nice to have a programmable support for HTML classes.
Suppose I have HTML which includes classes:
<strong class="notice">Important information</strong>
We could have a framework where we could program instances of classes, and how to render them in BBCode.
For example, class="notice" could be wrapped in red colour:
[b][color=#FF0000]Important information[/color][/b]

The library could thus be made class aware. The user could register a class and tell the library how to render it. When the converter finds a class, it looks up if it is among registered classes, and handles it appropriately.

Would you be interested in some PR's?

Hey I'm working on a project that needs to convert a forum from BBcode to Markdown, there are some items not handled here. I know this project is quite old. Would you be interested in PR's or would you prefer if I just fix it on my for and leave it alone?

Thanks for the code and have a super day!

<a> tags with no href

Hello, I'm trying to use your converter (thank you) to convert some code, but the problem is it has some tags without href, for which your library throws a malformed link exception. The in the code I want to convert are like:

<a rel="nofollow">4d10f06 </a>

The little research I have done says points that that is valid HTML.

Bare links wrapped in [url] don't get converted

Thanks for your library, it helped me a great deal.

However, this should either be converted to Markdown link ([https://github.com](https://github.com)) or the URL tags should be stripped:

$input = '[url]https://github.com[/url]';
$Converter = new \Converter\BBCodeConverter($input);
$output = $Converter->toMarkdown();
// $output == $input

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.