Chapters
23 Chapters
|
2:20:28
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
02.
KnpMarkdownBundle & Service
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
This tutorial also works great for Symfony 6!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.3.0 || ^8.0.0",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.1
"sentry/sentry-symfony": "^4.0", // 4.0.3
"symfony/asset": "5.0.*", // v5.0.11
"symfony/console": "5.0.*", // v5.0.11
"symfony/debug-bundle": "5.0.*", // v5.0.11
"symfony/dotenv": "5.0.*", // v5.0.11
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/framework-bundle": "5.0.*", // v5.0.11
"symfony/monolog-bundle": "^3.0", // v3.6.0
"symfony/profiler-pack": "*", // v1.0.5
"symfony/routing": "5.1.*", // v5.1.11
"symfony/twig-pack": "^1.0", // v1.0.1
"symfony/var-dumper": "5.0.*", // v5.0.11
"symfony/webpack-encore-bundle": "^1.7", // v1.8.0
"symfony/yaml": "5.0.*" // v5.0.11
},
"require-dev": {
"symfony/maker-bundle": "^1.15", // v1.23.0
"symfony/profiler-pack": "^1.0" // v1.0.5
}
}
38 Comments
Hello, when you use Knp markdown to HTML, it embeds the text in a <p> tag. So
{{ "text"|markdown }}gives<p>text</p>.However, it is impossible to have one <p> tag inside another <p> tag. So in the example of this course, it first generates an empty
<p class="d-inline"></p>, then the <p> tag with the transformed markdown.If we want to keep previous display, we would need to put the class d-inline into the generated <p> tag.
Hey Antoine R.!
Ah, good catch on that! That's my fault - I was sloppy! What we should have done is change the
<p class="d-inline"></div> into adiv` to avoid this problem :).Cheers!
Hello,
I tried that, and even with a div instead, as the generated <p> tag has not the class inline, it still goes below the quote instead of going on the same line ! I think the best way to have the question on the same level as the quote is to use a englobling div with a class that gives display: inline to its child.
Hey Antoine R.
What you say makes sense to me. Did it work?
Hi,
I just tried it. It works well. However, the element englobing our generated html must be inline too, so I used a span instead of a div.
Great! Thanks for sharing it!
Hey :)
In order to get the MarkdownBundle to work, I had to reboot phpstorm. It was not recognized automatically before that. Any reason why ? I guess I missed something.
Ty. Same problem with Visual Studio Code. Autowiring MarkdownParserInterface didnt work untill I restarted VS. Before you go crazy try restarting :D
Hey Zeljko!
> Before you go crazy try restarting :D
Haha, that's my favorite, yeah! Thanks for sharing your solution with others :)
Cheers!
Hey Boris,
Well, PhpStorm caches a lot of files in your project to work faster, and most of the time it regenerate the cache on file change, but sometimes it might not I suppose, especially if you use some kind of virtualization like Docker, etc. So, rebooting may work, though it's really very rare cases I think. Or, sometimes new versions may bring some minor bugs that may cause this - that just happens, that's why keep it up to date is always a good idea :)
Anyway, thank you for sharing your solution with others!
Cheers!
Why isn't KnpMarkdownBundle one of Symfony Flex's contrib bundles? There are other bundles from knplabs on there, so I was just wondering.
Hey Jack!
Not every bundle should have a Symfony Flex recipe. Even without any recipe, the bundle will be anyway configured by Symfony Flex: installed and registered in your bundles.php. So, if the bundle does not need any required config, i.e. has good defaults that are rarely changed like in this KnpMarkdownBundle - the maintainers decide to not add a recipe for it - less files in your system, yay! But of course, those who need to configure something - still can do it easily by adding a config file manually.
I hope it's clear for you know!
Cheers!
Now, I tried following the instructions in the video, but at the end it's the same old text with no bold words. I tried to add code in this comment box but I couldn't. I wanted to continue writing simple text but couldn't get out of Code Block 🙂
No changes. What am I missing?
Never mind. It turned out I was editing looking into the wrong page 🙂
Hey Ashatou,
Great, I'm glad you figured the problem out :) Sometimes it might be also a cache problem, so it's a good idea to clear the cache first to see if it helps ;)
Cheers!
Hello,
- When I launch the server with "symfony serve -d" : I can't find a tutorial to solve this : " A new Symfony CLI version is available (5.4.12, currently running 5.4.8)... and then I have a warning : " [WARNING] The local web server is optimized for local development and MUST never be used in a production setup. "
-I don’t know if it’s related but when I launch the web site, symfony profiler announces me 160 deprecations, 1 error, 25 debug...
In advance, thank you
@there , hi, now that the markdown bundle from knp is abandoned, do you have any advice on whether to stick with the abandoned bundle or use the underlying michelf package and how to do that? The recommended twig replacement is not a drop-in replacement as the MarkdownParserInterface is not exposed.
Hey gazzatav!
There's no real harm in sticking with the abandoned bundle... it's SUPER stable, so I wouldn't sweat it too much. If I were to replace it, I would:
A) Install https://github.com/twigphp/markdown-extra
B) If you only have Michelf installed, then the new Twig filter should magically start using it.
C) If you're rendering markdown in PHP - and need an autowireable service - try registering one manually. I would add:
Let me know if that helps - the markdown-extra works well, but it's also simple - so you may need to do more work if you have things customized a bit :).
Cheers!
ok quick question:
"composer require knplabs/knp-markdown-bundle" installed all this thing, but did not add that line into bundles.php
I did that manually and it's ok but maybe anyone knows why is that? I have PHP 8< and Symfony 6< versions
Hey Jan,
Hm, it should add that line, probably at some point you hit "No" when Composer asked you if you would like to execute a recipe. It might just remember your answer, depends on what you typed, and then do not ask you anymore. Well, not a big deal, adding it manually should be fine too, good catch on how to do it
Cheers!
Hello. What is the difference from markdown.parser.max and markdown.parser.light? Thanks in advance
Hey zahariastefan462
The features which are enabled by default. You can find exact configuration here https://github.com/KnpLabs/...
Cheers!
Why do not install Markdown service using Flex system? Why KnpMarkdownBundle isn't present in flex.symfony.com?
Hey Janek
Flex doesn't installs services it helps you to configure bundles, which needs some additional configuration. You can read Victor's answer above as it describes perfectly this situation =)
Cheers!
Hello! I'm facing an error while running "composer require knplabs/knp-markdown-bundle" this is what I'm getting:
Please anyone advise on how to fix this?
Hey Norris,
Did you download the course code and start from the start/ directory? Or do you follow this course on your own project? What version of Symfony do you have? Depends on your Symfony version, probably you can specify a specific version of the bundle and install it, looks like Composer unable to resolve it manually. Or as a possible solution you may do what the error message suggest you, i.e. run:
composer require knplabs/knp-markdown-bundle --with-all-dependencies
But this will upgrade your dependencies that sometimes may also require some extra work, depends on the constraints you use in your composer.json file.
Cheers!
Hi Victor, I used composer require knplabs/knp-markdown-bundle --ignore-platform-reqs and it worked. Thanks for the assistance.
Hey Norris,
Glad to hear you were able to resolve this, and thanks for sharing your solution with others! For learning purposes it should be ok, but if you want to deploy this project to production someday - it would be better to resolve this problem in a different way, ignoring platform requirements may lead to unexpected problems.
Cheers!
Hey Victor,
Thanks for the heads up.
Cheers.
Great tutorial, but when using the following it rips away the markdown entered. Suggestions?
questionText|striptags|markdownHey Matthew,
Don't use "striptags" filter? :) You literally strip tags first, and then the text without tags you're passing though markdown filter. If it works weird for you - try to debug it e.g. like {{ dump(questionText|striptags) }} - you will see the exact string that will be processed through the markdown filter. Does it look good to you? If no, please share the string and explain what do you mean about "away the markdown entered", I probably don't understand it completely.
Cheers!
git is not installed. Are you sure we are not missing any steps? On the previous video I also got an error that it couldnt vind '.' path in ./bin/console
Hey Farry
Does my other comment helped you out?
Hey, if I want to use my code on a production server, do I then have to install all the composer packages etc. completly new on this server?
Hey Samuel
Deploying on a production server is a big topic. But in 2 words you should deploy your code with lock files on server, and run install commands. With this lock files you will be sure that you get same package versions as you have on dev. SO it will work.
Cheers!
"Houston: no signs of life"
Start the conversation!