2

I am having a hard time figuring out how to do this...

I am essentially saving a huge blog post in a property called "Body" in a class called "Post". In body I will have various things like

<p> Hello world </p>
<p> Some random paragraph </p>
<codeblock> Here is an example of a basic HTML page
<html>
<body>
<h1> Hello Guys ! </h1>
</body>
</html>
</codeblock>

Then I want to have a code block and thus I want the HTML/CSS/Javascript/etc to just be parsed to the page as HTML encoded/decoded so I literally want the tags and angle brackets to show up on the page instead of being parsed as whatever they are.

I also have a HTML tag called which is ended by . It's nothing special it just indents and adds some specific CSS with it. I want the markup before the and after the tag to render the HTML tags as necessary.

Currently I am literally outputting the contents of the Body property using

@Html.Raw(post.Body)

Nothing special when I save it to the DB:

@Html.TextAreaFor(model => model.Body)
12
  • If I understand this correctly, you want to show the raw version (which will let the browser parse the markup as html) with @Html.Raw(post.Body) and the version where its not parsed @Html.Display(post.Body) or @Html.DisplayFor(model => model.Body) where the tags are escaped. Commented Feb 16, 2015 at 6:55
  • Correct @janhartmann Commented Feb 16, 2015 at 7:03
  • I want to post both the raw: Html.Raw(post.Body) but somehow within that block I want to also parse portions just as @Html.Display.... Commented Feb 16, 2015 at 7:04
  • I think I might just try Google's Prettify css/js files and see if that works better. Thoughts? Commented Feb 16, 2015 at 7:05
  • 1
    Can you use <pre></pre> in your markup? Commented Feb 16, 2015 at 7:09

1 Answer 1

3

So for those that are still having this issue, this is how I resolved it.

1) I included prettyprint. See link below

https://google-code-prettify.googlecode.com/svn/trunk/README.html

2) When editing a post I just add the following code //Bunch of code

Example: var http = require("http");

var server = http.createServer(function(req, res){
console.log(req.url);
resp.write("<html><body>" + req.url + "</html></body>");
resp.end();
});

server.listen(3000);

</pre>

In my Razor View I have the following code:

<div class="blog margin-bottom-40" onload="prettyPrint()">
//Bunch of other code up here for my view
    <div class="blogpost">
        @Html.Raw(post.Body)
    </div>
</div>

My blog is www.techiejs.com

Feel free to have a look and if you need another file from my solution let me know. Currently my git repository is private.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.