Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: [MOD] Markdown Mod/Hack (sNews 1.5)  (Read 7065 times)

stefanish

  • Newbie
  • *
  • Karma: 0
  • Posts: 3
[MOD] Markdown Mod/Hack (sNews 1.5)
« on: January 18, 2007, 01:34:06 AM »

I'm not really a programmer, but I really prefer to have a simple syntax for editing (textile or markdown) and all of the mods here were for FKC or tiny MCE which are too fancy and always provide too much "stuff" for my preferences.

I looked into markdown, and after playing with the code a bit got it to allow for Markdown syntax to be used.

This is for Developers version: 1.5.30 Stable

1. I started by downloading PHP Markdown (http://www.michelf.com/projects/php-markdown/)

2. I uploaded it to my root directory.

3. I added the following line to index.php

include_once "markdown.php";

4. I added the Markdown function call to a number of instances (not all of them) of  "$text" in snews.php

Because I was really just hacking my way though I kept going till it worked I've included the line numbers here if someone who knows what they are doing wants to clean it up or make it more robust...

Lines:
458
1110
1314
1315
1580

you can download my source here: http://analogish.com/snews.php.txt
(replace the database variables at the top with your own)

5. It works.

Known issues i'd love to solve, but which are beyond my abilities to troubleshoot:

- When creating a new page or article the Markdown syntax cleanly displays, however if you edit an article or page the Markdown code has been translated to HTML code which is ugly, and hard to work with (it would be great if the text was parsed back out to Markdown syntax)
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[MOD] Markdown Mod/Hack (sNews 1.5)
« Reply #1 on: January 18, 2007, 10:22:19 AM »

sounds like a great tool, I just got to ask... I'm no friend of different vocabulary, and I seldom understand what things mean until I actually see them :lol: wouldn't this mod do the same as Key's html entities converter ? I've one up on m site: http://p-ahlqvist.com/htmlconv.php
Logged
"It's only dead fish that goes with the flow... "
Updated

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
[MOD] Markdown Mod/Hack (sNews 1.5)
« Reply #2 on: January 18, 2007, 05:00:31 PM »

Quote from: Patric
sounds like a great tool, I just got to ask...  wouldn't this mod do the same as Key's html entities converter ? I've one up on m site: http://p-ahlqvist.com/htmlconv.php
No... not quite the same purpose... but similar in concept. The HTML Entity Converter replaces specific elements with HTML entities and provides you with output you can copy and paste into another textarea in your sNews Admin panels (or into an html file). The markdown.php file does a similar job in that it replaces certain simple elements... used in the sNews Admin textareas... with compliant (X)HTML markup so that it displays (from the database) in the content containers as intended (bold, italic, headings, lists, etc.).

The markdown.php file itself is a biggie... much bigger than snews.php... at 2,734 lines (including the comments) broken into about 90 functions.Here is a brief description from within the comments at the bottom of the file:
Quote
Markdown is a text-to-HTML filter; it translates an easy-to-read / easy-to-write structured text format into HTML. Markdown's text format is most similar to that of plain text email, and supports features such
as headers, *emphasis*, code blocks, blockquotes, and links.

Markdown's syntax is designed not as a generic markup language, but specifically to serve as a front-end to (X)HTML. You can use span-level HTML tags anywhere in a Markdown document, and you can use block level HTML tags (like <div> and <table> as well).
I have not tried using it yet... I've just explored the file's contents and the the concept behind it. It does offer the site Admin a simpler mark-up alternative to using HTML.
« Last Edit: January 31, 2008, 11:41:32 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Craig Rodway

  • Newbie
  • *
  • Karma: 0
  • Posts: 6
    • http://webman.me.uk/
[MOD] Markdown Mod/Hack (sNews 1.5)
« Reply #3 on: January 21, 2007, 12:50:20 AM »

I totally agree with stefanish on the WYSIWYG point, a web development pet-hate of mine if you will ;)

I created a Textile (similar to Markdown) mod for 1.13 a while ago but never got round to publishing it, mainly because I got too busy; but I don't think it worked 100%, and it lacked the "preview" functionality (I now think this is possible by AJAX POSTing to a separate page which returns the formatted HTML).

Thanks for this insight into Markdown, I'll be giving Textile another go soon and post the results here :)
Logged
Craig Rodway, IT Support, Bishop Barrington School.

jlaudun

  • Newbie
  • *
  • Karma: 0
  • Posts: 10
[MOD] Markdown Mod/Hack (sNews 1.5)
« Reply #4 on: July 08, 2007, 11:50:04 PM »

I'm interested in this MOD/hack to use Markdown instead of html within an entry in the mySQL database. My question is this: wouldn't it be better to include the markdown.php in the index.php page?

I'm a php noob, so forgive the potential stupidity of this question.
Logged

Joost

  • Guest
[MOD] Markdown Mod/Hack (sNews 1.5)
« Reply #5 on: July 09, 2007, 03:22:24 AM »

Quote from: jlaudun
I'm interested in this MOD/hack to use Markdown instead of html within an entry in the mySQL database. My question is this: wouldn't it be better to include the markdown.php in the index.php page?

I'm a php noob, so forgive the potential stupidity of this question.
Stupid questions don't exist, stupid answers do, so I am the one that should be careful here. :)
The script would probably behave the same. However, it is always good to have different code languages separated as much as possible. That way php coders can focus on php (backend) and front end designers can focus on xhrml and css. Imagine you have to style a 40kb index.php file with only 1kb of xhtml, scattered all over the file. That's a real pain.
I am now in the middle of a project, where I have to style such file. It is even worse: the navigational menu is coming from a relational database and is written in 6kb optimized xml (spaghetti code) . So now I have to process amounts of  pages to see what kind of elements, classes and id's I have to style.

The short answer: If it works for you, go ahead.
Logged

sevenupcan

  • Newbie
  • *
  • Karma: 0
  • Posts: 20
Re: [MOD] Markdown Mod/Hack (sNews 1.5)
« Reply #6 on: November 10, 2008, 06:33:13 PM »

Has anyone tried this in sNews 1.7 yet? I don't really understand the php code much but I'm willing to experiment. What am I looking for when I add the Markdown function?
Logged

sevenupcan

  • Newbie
  • *
  • Karma: 0
  • Posts: 20
Re: [MOD] Markdown Mod/Hack (sNews 1.5)
« Reply #7 on: November 10, 2008, 06:54:08 PM »

Hi,

Has anyone atempted to get this to work in sNews 1.7?

I've had a go and managed with some success but not sure where else it would be useful...

So far I have only added the function so that it changes the article text (line 1927 of snews.php) as I'm not sure what the rest of the variables effect.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Markdown Mod/Hack (sNews 1.5)
« Reply #8 on: November 10, 2008, 09:06:13 PM »

Hi, Has anyone atempted to get this to work in sNews 1.7?

Sorry... I can't help you. Although I did look into the file some time ago (see post above) I never really found a practical use for it so never used it with 1.6 or 1.7.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

sevenupcan

  • Newbie
  • *
  • Karma: 0
  • Posts: 20
Re: [MOD] Markdown Mod/Hack (sNews 1.5)
« Reply #9 on: November 13, 2008, 02:12:55 PM »

Hi sorry I didn't mean to double post.

I've managed to get it to work when editing an article. Just need to find out how to get work when creating an article and pages

I find this useful for writing articles as I don't need to think too much about the markup of an article. For example if I write an article that has h2s and h3s as well as a few list items and maybe even the odd abbriviation I can write much more fluently.

For example...

## This is my h2 header

Lorem ipsum dolor sit amet, consectetuer SDK adipiscing elit. Fusce id purus sed elit rutrum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse.

### This is my h3 header

- list item 1
- list item 2
- list item 3

*[SDK]: Software Development Kit
Logged