Markdown - PHP parser [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Do you know about some markdown PHP parser, with code highlight, etc, like the GitHub markdown parser or https://stackedit.io/editor?
If it is available via Composer then better.
I've tried:
https://packagist.org/packages/michelf/php-markdown
https://packagist.org/packages/league/commonmark
https://packagist.org/packages/erusev/parsedown
but the result of all these are almost plain text.
The best result belongs to michelf/php-markdown as you can see on the following image:
$ composer require michelf/php-markdown
---
use Michelf\MarkdownExtra;
$parser = new MarkdownExtra();
$html = $parser->transform($markdown);
echo $html;
[EDIT 1]
Now I'm almost at my goal.
I used:
https://github.com/sindresorhus/github-markdown-css
And now I get a result very similar to GitHub but the code is not getting highlighted (with colors) according the corresponded language (on this case: html) as you can see on the following image:
Then my QUESTION now is:
what extra step do I need to do in order to get code syntax highlight like GitHub does?. Please, check the following GitHub's output:

I guess you are missing CSS styles for the rendered HTML.
The generated HTML looks actually ok.
Try to include the styles in the document where you echo the $html.
For example use Github styles like this:
https://github.com/sindresorhus/github-markdown-css

Related

I wanted to make a blog in pure react js and Nodejs(express,mongodb) . Also i can post code snippets and heading rather than a simple text [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
An example of a blogpost
Example of Blog post
If you want to use pure React, you might want to use something like Create React App, or Vite + React. You can pull in a Markdown library like react-markdown to parse blog posts.
I would also recommend using something like Astro (https://astro.build/), which can parse markdown and React natively.
you could use libraries like CKEditor, and Quill for advanced editors where you could add some images, and code snippets. and send the value of that editor to your server.
but you might like react-markdown if you don't like editors.

Language change on website best way [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I am making a website where I need to include a language change button from Hungarian to English.
Now my question is which is the best way to do that.
I mean should I just make new HTML files with different language or is there a better way to do it. I found some solution with Javascript but they used blocks which is not good for me because I have to change a lot of texts and some PHP solution but I have never used PHP yet.
Best would be a solution with Javascript or Node.js or something that I can learn fast :D
Dump all the content of the page to a string or some data structure and then by using the module "translate" you can translate it to any other language. It provides translation to multiple languages then on button click translate the text and send back as response and set the text on the client side. You can install it by:-
npm install --save translate
A sample code for that will be:-
// 'es' can be a language string or an object like { to: 'es' }
translate('Hello world', 'es').then(text => {
console.log(text); // Hola mundo
});
You can find more help here:-
https://www.npmjs.com/package/translate

PhantomJS only output part of the HTML [duplicate]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have 3 different files in my project and the layout is
phantomjs
-->phantomjs.js
-->phantomjs.exe
index.php
index.php:
$phantom_script = dirname(__FILE__). '\phantomjs\phantomjs.js';
$response = exec ('\phantomjs\phantomjs.exe' . $phantom_script);
echo $response;
phantomjs\phantomjs.js
var webPage = require('webpage');
var page = webPage.create();
page.open('http://www.google.com', function(status) {
console.log(page.content);
phantom.exit();
});
your usage oh phantomjs is correct according to the documentation.
http://phantomjs.org/api/webpage/property/content.html
php exec method returns the last line only.
Maybe that line is a white space.
http://php.net/manual/fr/function.exec.php
You shall have a seond parameter &$output, sent by reference. It is an array containing the entire output.
A problem you may face later, the content could need be to evaluated before you try to read it s DOM document content. Using for example innerHTML of HTML tag, ie: $('html').html();
If the page does not have jquery, you may include it, see this example, https://github.com/ariya/phantomjs/blob/master/examples/phantomwebintro.js
Note also that google may actively desire to not let users scrap and save their search results. Not sure about that.

How to write TypeScript and CoffeeScript in Brackets? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to write TypeScript and CoffeeScript in the Brackets code editor, but I am having difficulties. How do I compile it to vanilla js? How to refer it in the html page?
For TypeScript
intellisence / syntax highlighting / live error checking
You need the brackets-typescript plugin : https://github.com/fdecampredon/brackets-typescript
Compile to vanilla JS
You can use grunt to do that for you : https://github.com/grunt-ts/grunt-ts. It can compile your project whenever you save a file in brackets (or any other editor). The output is JavaScript
How to refer it in the html page
You point to the generated JS with a normal script tag as you do if you were just using JavaScript to begin with.
Alternatively you can use something like RequireJS http://requirejs.org/

How to check which part of page is an article? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I would like to create a similar tool to Instapaper or Readability and I wonder what is the best way to find and get text from a web page. Do you have any ideas?
The question is too broad to give a concrete answer to, but you can separate this question into three concerns:
A way to grab web resources. libcurl for example, or just about anything able to talk HTTP.
A DOM parser. Python has xml.dom.minidom, for example.
An algorithm for traversing the DOM tree and extracting text. Be it scanning for elements with class=article, or <div>s with more than 1024 characters etc., is entirely up to you. You will need experimentation to get this right.
I suggest asking separate questions for each of these concerns. After doing research on each, of course. :)
Here is an idea to get you started in Ruby. Just tested the code below and it is working fine for me. Have a look it might help you.
require 'open-uri'
require 'cgi'
require 'nokogiri'
$url='http://www.stackoverflow.com'
$txt_file = open($url)
$raw_contents = $txt_file.read
$html = Nokogiri::HTML(CGI.unescapeHTML($raw_contents)).content
#strip the web page fetched out of all hmtl tags and encoded chars
$txt_file = File.new('c:\ruby193\bin\web-content\stack.txt', "w")
#stack.txt now contains a stripped, pure txt file which you can manipulate further
$txt_file.write($html)
$txt_file.close
puts 'Here is the stripped text of your webpage\n'+$html

Categories

Resources