Replace size parameter in css - c#

I want to replace all font-size-parameters in a html document (css attributes).
I'm using .net with c#.
I guess it could be done with some regular expression.
Am I forgetting some other ways to set the font size?
Example:
<html>
<head>
<style type="text/css">
.t {
font-size: large;
}
</style>
</head>
<body>
<span style="font-size: medium" />
</body>
</html>
into:
<html>
<head>
<style type="text/css">
.t {
font-size: large_replaced;
}
</style>
</head>
<body>
<span style="font-size: medium_replaced" />
</body>
</html>

if you use relative unit like em, ex etc for all font dimensions in your page. By adjusting
only html elements' size you manage all fonts
big fonts
html{
font-size:18px;
}
smaller fonts
html{
font-size:18px;
}
you can manage that form javascript, better (also using cookies).

I ended up using the following regex to find where to replace:
/style=\"[.]*font-size:(?<size>[^;]*);[^\"]*[\"]/
/<style[^<]*font-size:(?<size>[^;]*);[^<]*[<]/

Related

Blazor - Writing text to background

I am trying to write text to the background of a blazor application.
I want it to show all my method calls in the background (so it looks techy!)
Does anyone know the best way to do this? I have researched but found nothing as of yet.
On the HTML/CSS side, it should be something along these lines:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
#content{
position: absolute;
top: 0%;
left: 0%;
font-size: 50px;
color: black;
-ms-transform: translate(-50%,-50%);
}
#background{
color: darkgray;
}
</style>
</head>
<body>
<div id="background">
This is my<br/>
background<br/>
content ...<br />
</div>
<div id="content">
This is my overlay content.
</div>
</body>
</html>
Two content blocks are created with the div tags: one for the foreground and one for the background. JavaScript can then be used to animate/adjust the background content accordingly to get your required effect.

Get full source of a webBrowser

I have a webBrowser:
webBrowser1.DocumentText = #"<html lang='en'>
<head>
<meta charset='utf-8'>
<title></title>
<style type='text/css'>
.red
{
color: red;
}
</style>
</head>
<body>
<div class='red'>red text</div>
sad adad a das
</body></html>";
I want to get the full source of the webBrowser:
textBox1.Text = webBrowser1.DocumentText;
But it results only:
<HTML></HTML>
It works if I display in a MessageBox before set the textBox1.text:
MessageBox.Show(webBrowser1.DocumentText);
It's weird. How can I get the full source?
Here is a proper way to display HTML from string in WebBrowser control
var html = #"<html lang='en'>
<head>
<meta charset='utf-8'>
<title></title>
<style type='text/css'>
.red
{
color: red;
}
</style>
</head>
<body>
<div class='red'>red text</div>
sad adad a das
</body></html>";
webBrowser1.DocumentText = "0";
webBrowser1.Document.OpenNew(true);
webBrowser1.Document.Write(html);
webBrowser1.Refresh();
// Will return html you provided
textBox1.Text = webBrowser1.DocumentText;
To answer your initial question directly, how to get FULL SOURCE no matter what:
WebBrowser1.Document.GetElementsByTagName("HTML").Item[0].OuterHtml;
Make it a habit to use this and NOT DocumentText because if you make any changes to DocumentText after it's been set, for example, changing the InnerHTML of a tag, those changes wont save to DocumentText.
I just slapped a TextBox onto one of my WinForms and updated the text to the above code and it shows all my HTML without issue. Here's an example of me filling in my WebBrowser in case you've got a typo or something in your code:
WebBrowser1.Navigate("about:blank");
WebBrowser1.Document.OpenNew(false);
WebBrowser1.Document.Write("<html><head><title></title></head><body></body></html>");
I never had any luck writing the DocumentText directly. This method worked without issue.

unable to get css when sending email with css

is there any way you can send an email from c# asp.net with a html page with css.
Currently I am sending the email but when I open in gmail it does not capture the css included in the htmlpage
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
body{
background-color:navy;
color:white;
font-family:Menulis;
margin-left:40px;
}
div {
margin:0 auto;
}
img{
border-radius:5px;
width:200px;
height:300px;
margin-right:200px;
display:block;
float:right;
}
</style>
</head>
<body>
<div>
<h1>User {user_email} Error Report</h1>
<p>The following error occured when user is trying to reset password
from pswrd_recover.aspx page:</p><br/>
<img src="https://pcappliancerepair.files.wordpress.com/2016/11
/38644550_m.jpg?w=585"/>
<p>{error_message}</p>
</div>
</body>
</html>
Gmail removes the entire head portion of your email’s HTML. So, it will also remove any style elements.
You need to inline your CSS, like this:
<body style="background-color:navy; color:white;font-family:Menulis;margin-left:40px;">
<div style="margin:0 auto;">...</div>
<img style="border-radius:5px;width:200px;height:300px;margin-right:200px;display:block;float:right;" src="https://..." />
</body>

Unable to dispaly markers on map using mapbox ,leaflet Omnivore

I am trying to use CSV file to display markers on map using mapbox and leaflet. I found one example in mapbox documentation , I am trying to use the same example , I just changed the CSV file but it is not displaying markers on map. I just started using map box so desperately looking for some help.
my CSV file looks like this
Value,FacTy,Latitude,Longitude
1,112,42.27426,-83.365717
2,113,42.274082,-83.3623
3,30,42.337196,-83.487672
Here is my code snippest
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Loading markers from CSV</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.2.0/leaflet-omnivore.min.js'></script>
<div id='map'></div>
<script>
var map = L.mapbox.map('map', 'examples.map-i86nkdio')
.setView([42.274082, -83.362300], 8);
omnivore.csv('latlon.csv',null,L.mapbox.featureLayer()).addTo(map);
</script>
</body>
</html>
Looks like you're missing a linebreak before the first row of your data. Here's a fixed example.
Value,FacTy,Latitude,Longitude 1,112,42.27426,-83.365717
2,113,42.274082,-83.3623
3,30,42.337196,-83.487672
should be
Value,FacTy,Latitude,Longitude
1,112,42.27426,-83.365717
2,113,42.274082,-83.3623
3,30,42.337196,-83.487672
I was having the same issue as you, and then realized that it was a problem with the data. In order to log those errors on the console, you have to use:
omnivore.csv('your_file.csv', null, L.mapbox.featureLayer()).addTo(map)
.on('error', function(error) {
console.log(error);
});
And it will tell you which line is not working, such as an invalid lat or long. More info.
Hope this helps!

WatiN read attribute from iframe's body

Is there a way to read the style attribute of body inside an iFrame?
I've tried using multiple combinations of Body, NativeElement, Frame and other Properties, but so far I had no luck.
<iframe id="iFrame" width="100%" height="500" frameborder="0" src="some source">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body style="margin: 0px; padding: 0px;height:500px;">
</body>
</html>
</iframe>
Example:
_browser.Frame(Find.ById(frameId)).Body.GetAttributeValue("style")
Iframe may be inside a different form, did you tried?
it happend once to me, the iframe was in a different form(nested form)

Categories

Resources