How do I parse GitHub markdown to PHP from a URL? - php

I can already parse a Markdown file to HTML but my problem is getting that markdown file from a URL instead of a local file.
Below is the code I have:
<?php
include('./includes/Parsedown.php');
$Parsedown = new Parsedown();
$text = 'https://raw.githubusercontent.com/dylanwe/How-to-make-a-discord-bot/master/README.md';
$slug = 'How-to-make-a-discord-bot';
$text = str_replace('img', "https://raw.githubusercontent.com/dylanwe/$slug/master/img", $text);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/themes/prism-coy.min.css">
<link rel="stylesheet" href="css/prism_github.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/4.0.0/github-markdown.min.css">
<style>
.markdown-body {
max-width: 780px;
margin: 0 auto;
padding: 15px;
}
pre[class*=language-]>code {
border: none;
box-shadow: none;
}
</style>
<title>Document</title>
</head>
<body>
<div class="markdown-body">
<?php echo $Parsedown->text($text); ?>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/prism.min.js"></script>
</body>
</html>

It's not very clear what isn't working as expected, but it looks like you just need to retrieve the contents of the Markdown file, e.g. using file_get_contents():
$text = file_get_contents('https://raw.githubusercontent.com/dylanwe/How-to-make-a-discord-bot/master/README.md');

Related

My css class code doesnt works, it should at be the bottom but it's now working

Php code
i searched on the web and i didnt see anything about this it looks like no error css status is 200
css code is at the bottom.
.sagalt {
margin-top: 500px
}
<html>
<head>
<meta charset="utf-8">
<title>quantum</title>
<link rel="shortcut icon" href="logo.png" type="image/png">
<link rel="stylesheet" href="qntm.css?v=<?php echo time(); ?>">
<!--link//-->
</head>
<body>
<div>
Sign Out
</div>
</body>
</html>
Think you are trying to apply CSS to the link. Anchor tag being an inline element, margin top/bottom property alone wont have an effect in it as inline elements flow with content on the page. Use display: inline-block or display: flex or float: left as per your requirement.
.sagalt {
color: red;
margin-top: 100px;
display: inline-block;
}
<html>
<head>
<meta charset="utf-8">
<title>quantum</title>
<link rel="shortcut icon" href="logo.png" type="image/png">
<link rel="stylesheet" href="qntm.css?v=<?php echo time(); ?>">
<!--link//-->
</head>
<body>
<div>
Sign Out
</div>
</body>
</html>

I want css styles applied to child page body must not affect the parent page body?

I have php page in which another php page is embedded dynamically, both the pages have styles applied to its own body.
The final html is
<!DOCTYPE html>
<html>
<head>
<title>Email</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
text-align: center;
background-color: #f00;
}
</style>
</head>
<body>
<div>Text in main body</div>
<!DOCTYPE html>
<html>
<head>
<title>Email</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
text-align: left;
background-color: #0f0;
}
</style>
</head>
<body>
<div>Text in child body</div>
</body>
</html>
</body>
</html>
I want css styles applied to child body must not affect the parent body and vice versa.
I can edit main page only child page is not in my control and content of the child page is stored in a php variable.
You can wrap your parent content in div with class=wrap and style in css the .wrap
Note! this is invalid html because you can not set HTML inside another HTML
<!DOCTYPE html>
<html>
<head>
<title>Email</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
.wrap {
text-align: center;
background-color: #f00;
}
</style>
</head>
<body>
<div class="wrap">Text in main body</div>
<!DOCTYPE html>
<html>
<head>
<title>Email</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
text-align: left;
background-color: #0f0;
}
</style>
</head>
<body>
<div>Text in child body</div>
</body>
</html>
</body>
</html>

Upload system, similar to youtube

I'm trying to create an upload system similar to YouTube.
But in PDF. When you upload a video to YouTube, you create a page.
I already have a code for the page that would be the pdf. But I needed to know how I could create a page that does the upload and modify the html by changing the pdf link
* pdfListView.loadPdf ("/ upload / ebooks / 1.pdf"); *
Follow the code below
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Demo of pdfListView</title>
<style>
.page-container {
margin: 10px auto;
}
.page-view canvas {
box-shadow: black 0px 0px 10px;
}
</style>
<!-- File from the PDF.JS Library -->
<script type="text/javascript" src="external/compatibility.js"></script>
<script type="text/javascript" src="external/pdf.js"></script>
<script type="text/javascript">PDFJS.workerSrc = 'external/pdf.worker.js';</script>
<!-- Leave out the following two files if you don't need a textLayer -->
<link rel="stylesheet" href="src/TextLayer.css">
<script src="src/TextLayerBuilder.js"></script>
<!-- Leave out the following two files if you don't need an annotations layer -->
<link rel="stylesheet" href="src/AnnotationsLayer.css">
<script src="src/AnnotationsLayerBuilder.js"></script>
<!-- Core pdfListView file -->
<script src="src/PdfListView.js"></script>
</head>
<body>
<div id="main" style="position: absolute; top:0px; bottom:0px; left: 0; right: 0; overflow:scroll">
<!-- The pageContainers go here !-->
</div>
<script type="text/javascript">
window.pdfListView = new PDFListView(
document.getElementById("main"),
{
// Comment out the next line to get a listView without textLayer.
textLayerBuilder: TextLayerBuilder,
annotationsLayerBuilder: AnnotationsLayerBuilder,
logLevel: PDFListView.Logger.DEBUG
}
);
pdfListView.loadPdf("http://playofthegame.me/ebooks/A_HIST%c3%93RIA_SECRETA_DA_MA%c3%87ONARIA_E_ORDEM_ROSACRUZ_-_por_Jakim_Booz.pdf");
</script>
</body>
</html>

How to set css at time of PDF creation in yii2?

Pdf fuction*
This function is call from ajax after getting data from this function it's call anothe file here I am display data which is coming from data base.That file all css part in style tag using then as it is style tag prind in pdf as a text and if this all css file include in css folder then pdf is not create in proper format
public function actionInvoicespacking(){
$pdf = Yii::$app->pdf;
$modelShipment = Shipment::find()->orderBy('ship_id DESC')->one();
if(count($modelShipment) == 0) {
$shipid= 1;
} else
{
$shipid= $modelShipment->ship_id;
}
$htmlContent = file_get_contents('http://localhost/shepherdlogistics_v1.0/backend/views/shipment/invoicespackingdata.php');
$pdf->content = $htmlContent;
return $pdf->render();
}
invoicespackingdata.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Invoice</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.fontawesome.min.css">
<link rel="stylesheet" href="css/stylepdf.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
body {
font-size: 18px;
font-family: cambria;
}
.nopadd {
padding: 0px;
}
</style>
</head>
<body>
<div class="container">
<br>
<br>
<div class="">
<div class="col-lg-2 nopadd">
<img src="logopdf.png" alt="logo" width="100%">
</div>
<div class="col-lg-10">
<h1 style="font-size: 55px;font-weight: bold; padding: 23px 0px;">
SHEPHERD LOGISTICS CO. W.L.L.</h1>
</div>
</div>
</div>
</div>
As the demo states:
Any <style> tag will be skipped (you must use cssInline property for this)
If you have just a few styles to add to the pdf, you can pass it like this:
$pdf->content = $htmlContent;
$pdf->cssInline = '.class1 {color: red} .class2 {color:blue}';
But if you have alot of styles, you can also consider change the default cssFile to any file you want with the correct css. (by default, this property is #vendor/kartik-v/yii2-mpdf/assets/bootstrap.min.css

Filepathes after .htaccess creation

I have a filepath problem after the creation of a .htaccess protected admin directory.
Here is the structure of the folder:
file-controller4.php was initially at the root of the directory next to file-controller3.php and file-view4.php was in the view directory.
To call the header.php from file-controller4.php I use set_include_path.
The problem is that the header doesn't call the css file anymore which seems to be relative to the admin directory.
Here are the different files:
Admin folder:
file-controller4.php
<?php
set_include_path ( 'E:/xampp/htdocs/url/' );
include '/view/header.php';
include '/admin/file-view4.php';
file-view4.php
<h1>This is a title</h1>
Root folder:
file-controller3.php
<?php
include '/view/header.php';
include '/view/file-view3.php';
view folder:
file-view3.php
<h1>This is a title</h1>
header.php
<!DOCTYPE html>
<html lang="en">
<head>
<!--<meta charset="utf-8"></meta>-->
<meta http-equiv="Content-Type" content="text/html;" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<title>A TEST</title>
<link rel="stylesheet" type="text/css" href="css/css-example.css" ></link>
</head>
css folder:
css-example.css
html, body {
margin: 0;
padding: 0;
}
body {
background-color: white;
font-family: Verdana, sans-serif;
font-size: 100%;
}
h1 {
font-size: 200%;
color: navy;
text-align: center;
}
How could I load the CSS from file-controller4 like it does correctly with the file-controller3 ?
Thanks for your help.
You can check in header.php REQUEST_URI and detect where is script - in main folder or in admin. And then build url for CSS.
Like
<?php
if (strpos($_SERVER["REQUEST_URI"], "admin") !== false) {
$css_prefix = "../";
} else {
$css_prefix = "";
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo($css_prefix); ?>css/css-example.css" ></link>
But best and correct way is change logic of your application and move file-controller3.php inside folder admin

Categories