Bizarre hidden character in MVC3 Razor loop - asp.net-mvc-3

I have a loop
<ul id="news-list" class="thumbobs-list">
#foreach (var item in Model.News) {
#Html.Partial("RenderNews/" + item.TypeString, item)
}
</ul>
that uses partials like this
#model Web.Models.DataModel.NewsItem
#{ Layout = null; }
<li class="news-item #Model.TypeString.ToLower()" id="id-#Model.Id">
<h3 class="headline">
Example News headline.
</h3>
<p class="timestamp">#Model.TimeString</p>
</li>
that works great
but when i went to style with css i encountered a hidden whitespace character that is causing an issue
in front of each partial a space, a U+FEFF, and another space causing issues with the design.
has anyone ever seen this?

You have discovered the BOM, Byte Order Mark. It's stored as the first bytes in text files to indicate the encoding.
http://en.wikipedia.org/wiki/Byte_order_mark
[EDIT]
You can open a file with Notepad and "Save As..." as ANSI. This removes the BOM (and the encoding).
// reading a text file as binary will include the BOM flag
FileStream FS = new FileStream(MapPath(#"~\Text\TestUTF8.txt"), FileMode.Open);
byte[] Data = new byte[100];
FS.Read(Data, 0, 100); // BOM is in the data
FS.Close();
// get rid of the BOM
String String1 = System.Text.Encoding.UTF8.GetString(Data);
// reading a text file as text will automatically handle it.
String String2 = File.ReadAllText(MapPath(#"~\Text\TestUTF8.txt"));

Try copying the text out and create a new partial view. Paste it into notepad and rebuild your partial to rule out this character being hidden in your partial or simply load it on the vs binary editor and look for that character. Right click and open with... Then choose binary editor.

Related

How to force with iText7 a new blank page only when necessary in order to have each text exactly on two pages?

I'm using itext 7.2.1 and I've this situation: I have a list of letters with variable content that normally fits in one page, but occasionally can span over two pages.
My goal is to force a new blank page after the "short" letters so they start alway on odd pages. The length of text is not know in advance.
Basically I have the following code:
PdfWriter writer = new PdfWriter("letters.pdf");
Document document = new Document(new PdfDocument(writer));
List<String> letters = . . .code to retrieve letters text;
int nLetter = 0;
for (String text : letters) {
Paragraph p = new Paragraph().add(text);
doc.add(p);
nLetter++;
//now after layout of last paragraph I must ensure that
//the next paragraph starts on page (nLetter*2 + 1): how can I do this?
}
. . .
doc.close();
What is the best way to do so in iText7? I tried with custom DocumentRenderer but I haven't found a clean and working solution.
The best and simpliest way to know if your next paragraph starts on the next page of the document is to get the root renderer of your document and get current area. And it will return the area(rectangle and page) where the end of the text is located.
doc.getRenderer().getCurrentArea();

Razor (.cshtml) editor code block format settings

I am running Visual Studio 16.8.1, when editing a Razor .cshtml file and applying a reformat (CTRL+K+D) the editor moves braces and elements in a code block starting with #
For example if I have the code:
#{
Layout = "_Layout";
ViewData["Title"] = "My Page";
}
#if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>#Model.RequestId</code>
</p>
}
And I reformat the file by pressing CTRL+K+D it will move the fist line to the same line as the #{ and move the closing brace right after the last element like:
#{ Layout = "_Layout";
ViewData["Title"] = "My Page"; }
#if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>#Model.RequestId</code>
</p>}
Is there a way to control when VS inserts or removes new lines and indenting before and after the braces so it formats like the first example? I have searched through the Options->Text Editor->{editor}->Formatting groups and can't find anything that seems to control this behavior, is this a bug in the VS editor or am I just missing the setting somewhere?
This looks like it was fixed in Visual Studio Version 16.8.2

ckeditor removes new line characters from source

Using CKEditor 4.9.2 on a textarea, which already has content, separated by new lines (\r\n). When the CKEditor instance loaded, these new lines were removed like this:
<textarea name="message" >
row 1 text text text
row 2 text text text text text text
row 3 text text
row 4 text
row 5
</textarea>
I can't convert them to <br> tags, have to work with \r\n characters.
How can I keep the \r\n characters?
You can't preserve new line character in CKEditor, it is not regular textarea. It is displaying your content by using html elements on page and it cant work like you want.
Easy solution I can suggest would bo to replace all new lines with <br>.
editor.on( 'setData', function(event) {
event.data.dataValue = event.data.dataValue.replace( 'your regexp', '<br>' );
} );
And then after getting editor data, just replace each <br> with new line character.

TYPO3 getting image from page content

I'm working on my first TYPO3 project and I'm done with the template, I just can't figure out how to make this work:
My page content is one column with header, text and title in every field.
I don't have any problems showing header and text on my website, but the image just won't work.
My image-path is fileadmin/user_upload/ and I can show it by setting the filename in my code, but thats obviously not what I want.
This is my Content Object Array, the code for the image is one of the versions I found when searching, but none of them worked:
page.20 = CONTENT
page.20.table = tt_content
page.20.wrap = <div id="content">|</div>
page.20.renderObj = COA
page.20.renderObj.wrap = <div id="news">|</div>
page.20.renderObj {
10 = TEXT
10.stdWrap.field = header
10.stdWrap.wrap = <div id="newstitle"><span>|</span></div>
20 = IMAGE
20.stdWrap.field = image
20.stdWrap.wrap = <div id="newsimage><img src="fileadmin/user_upload/|"</img></div>
30 = TEXT
30.stdWrap.field = bodytext
30.stdWrap.wrap = <div id="newstext"><p>|</p></div>
}
Hope someone could help me out, so I can finally finish this project!
Maybe I don't understood correctly, but... you don't need to write it yourself, just in your main TS template include CSS Styled Content from extension, so you can render whole column like:
page.20 < styles.content.get
If you need to change some wrappings (i.e.: to add your news CSS classes) you can also override them in setup field.
edit: Go to Templates > Template analyzer and check the EXT:css_styled_content/static/ code to find declaration you'd like to change (prepare for looong reading ;)) when you finally find it, just you can overwrite it in your TS, ie: to wrap text section of Text w/ image CE you can use:
tt_content.textpic.20.text.wrap = <div class="myNewsClass"> | </div>
Finally I'd suggest not to replace original classes but add your own so the above sample would be like:
tt_content.textpic.20.text.wrap = <div class="csc-textpic-text myNewsClass"> | </div>
de facto all these classes csc- has some CSS default styling therefore you can choose to align the image to the left or right (etc) out of the box. If you'll remove it you'll need to handle these things yourself.

CKEditor: How to stop angle brackets from converting to HTML entities

Our site is using tags like <# TAGNAME #> but CKEditor converts < and > to &lt and &gt which breaks these tags for use in our software.
I've discovered this option: config.protectedSource.push( /<#[\s\S]*##>/g ); which seems to stop the conversion if the data is saved from Source mode, but in WYSIWYG mode I can't find a way to stop the conversion. I've tried many options in their API but none of them seem to have helped, how can I fix this problem?
Were were looking at using CKEDitor to edit Smarty templates. The problem we were hitting was that it was replacing all the angle brackets and ampersands within the curly brackets, which messed everything up. This came up in a Google search so our solution should help anyone with similar issues.
CKEditor rebuilds the HTML every time you switch to Source mode and when you save, so you need to add to the HTML http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Data_Processor htmlFilter.
This worked for us:
//replace Form_content with whatever your editor's id is.
htmlParser = CKEDITOR.instances.Form_content.dataProcessor.htmlFilter;
//We don't want HTML encoding on smarty tags
//so we need to change things in curly brackets
htmlParser.onText = function(text) {
//find all bits in curly brackets
var matches = text.match(/\{([^}]+)\}/g);
//go through each match and replace the encoded characters
if (matches!=null) {
for (match in matches) {
var replacedString=matches[match];
replacedString = matches[match].replace(/>/g,'>');
replacedString = replacedString.replace(/</g,'<');
replacedString = replacedString.replace(/&/g,'&');
text = text.replace(matches[match],replacedString);
}
}
return text;
}
The onText function processes all the bits that aren't in tags or comments.
I'd imagine you can do something similar by altering the code above - I've left it as is as I think our problems and required solutions are very similar.
editor.on( 'mode', function(ev) {
if ( ev.editor.mode == 'source' ) {
var str=ev.editor.getData();
str=str.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, "\"");
ev.editor.textarea.setValue(str);
}
});
http://cksource.com/forums/viewtopic.php?f=11&t=20647&start=10
If you type < or > in any WYSIWYG editor, they will be converted to their HTML entities in source mode.

Resources