Is it possible to export the content as an html snippet, the way your asp.net editor does?
The HtmlFormatProvider exports a full html document complete with DOCTYPE, etc.
This is a lot of bloat for my scenario, and actually is technically invalid as I display the saved content in a standard webpage.
Thanks,
Ari
The HtmlFormatProvider exports a full html document complete with DOCTYPE, etc.
This is a lot of bloat for my scenario, and actually is technically invalid as I display the saved content in a standard webpage.
Thanks,
Ari
6 Answers, 1 is accepted
0
Hello Ari,
Currently, the HtmlFormatProvider is designed to export valid XHTML documents, in the sense the specification defines "document", which includes doctype and other declarations. For your case, some processing will be needed. As our documents are valid XML, you should extract the CSS styles and the content of the body tag and place them in your page.
Let us know if you have any other questions.
Best wishes,
Ivailo
the Telerik team
Currently, the HtmlFormatProvider is designed to export valid XHTML documents, in the sense the specification defines "document", which includes doctype and other declarations. For your case, some processing will be needed. As our documents are valid XML, you should extract the CSS styles and the content of the body tag and place them in your page.
Let us know if you have any other questions.
Best wishes,
Ivailo
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Roland Klug
Top achievements
Rank 1
answered on 11 Aug 2010, 10:50 AM
Hi,
we had the same problem and so we implemented our own provider. Here ist our very simple implementation which has to be extended with further features.
Best regards
we had the same problem and so we implemented our own provider. Here ist our very simple implementation which has to be extended with further features.
public
class
SimpleHtmlFormatProvider : IDocumentFormatProvider
{
#region Implementation of IDocumentFormatProvider
public
RadDocument Import(Stream input)
{
return
new
HtmlFormatProvider().Import(input);
}
public
void
Export(RadDocument document, Stream output)
{
var html = GetHtmlOutput(document);
var bytes = Encoding.UTF8.GetBytes(html);
output.Write(bytes, 0, bytes.Length);
}
public
string
Name
{
get
{
throw
new
NotImplementedException(); }
}
public
IEnumerable<
string
> SupportedExtensions
{
get
{
yield
return
".htm"
;
yield
return
".html"
;
}
}
public
bool
CanImport
{
get
{
return
true
; }
}
public
bool
CanExport
{
get
{
return
true
; }
}
private
static
String GetHtmlOutput(RadDocument document)
{
var html = String.Empty;
foreach
(var section
in
document.Sections)
{
foreach
(var paragraph
in
section.Paragraphs)
{
if
(paragraph.IsEmpty)
{
html +=
"<br />"
;
continue
;
}
html +=
"<p>"
;
foreach
(var inline
in
paragraph.Inlines)
{
if
(!(inline
is
Span))
continue
;
var span = inline
as
Span;
var openTag = String.Empty;
var closeTag = String.Empty;
var content = HttpUtility.HtmlEncode(span.Text);
var style = String.Empty;
if
(inline
is
Hyperlink)
{
var link = inline
as
Hyperlink;
openTag =
string
.Format(
"<a href=\"{0}\" target=\"{1}\"{{0}}>"
, link.URL, GetTarget(link.Target));
closeTag =
"</a>"
;
}
if
(String.IsNullOrWhiteSpace(content))
continue
;
if
(span.FontWeight != FontWeights.Normal)
{
openTag +=
"<strong>"
;
closeTag =
"</strong>"
+ closeTag;
}
if
(span.Underline && !(inline
is
Hyperlink))
{
style =
" text-decoration: underline;"
;
}
if
(span.FontStyle == FontStyles.Italic)
{
openTag +=
"<i>"
;
closeTag =
"</i>"
+ closeTag;
}
if
(!String.IsNullOrEmpty(style))
{
style =
string
.Format(
" style=\"{0}\""
, style.Trim());
if
(inline
is
Hyperlink)
{
openTag = String.Format(openTag, style);
}
else
{
openTag +=
string
.Format(
"<span{0}>"
, style);
closeTag = closeTag +
"</span>"
;
}
}
else
if
(inline
is
Hyperlink)
{
openTag =
string
.Format(openTag, String.Empty);
}
html += openTag + content + closeTag;
}
html +=
"</p>"
;
}
}
html = html.Replace(
"\n"
,
"<br />"
).Replace(
"\r"
,
string
.Empty);
return
Regex.IsMatch(html, @
"^<p>[\s]*</p>$"
) ? String.Empty : html;
}
private
static
String GetTarget(HyperlinkTargets target)
{
switch
(target)
{
default
:
case
HyperlinkTargets.Self:
return
"_self"
;
case
HyperlinkTargets.Blank:
return
"_blank"
;
}
}
#endregion
}
Best regards
0
Hello Roland Klug,
We have received some requests to support HTML exporting of document excerpts, so we have added this to our to-do list. It will be available in the next release (at the latest - Q3 2010).
Get back to us if you have other questions.
Greetings,
Ivailo
the Telerik team
We have received some requests to support HTML exporting of document excerpts, so we have added this to our to-do list. It will be available in the next release (at the latest - Q3 2010).
Get back to us if you have other questions.
Greetings,
Ivailo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Cyprian
Top achievements
Rank 1
answered on 30 Nov 2010, 04:24 PM
Did "Export HTML snippet" mis Q3 release? We are interested in this functionality to avoid writing out own custom provider.
0
Hi Cyprian,
We have included this functionality in the Q3 release. You can access it like this:
Let us know if you require further assistance.
Best wishes,
Ivailo
the Telerik team
We have included this functionality in the Q3 release. You can access it like this:
HtmlExportSettings exportSettings =
new
HtmlExportSettings();
exportSettings.DocumentExportLevel = DocumentExportLevel.Fragment;
HtmlFormatProvider formatProvider =
new
HtmlFormatProvider();
formatProvider.ExportSettings = exportSettings;
.. formatProvider.Export(document); ...
Best wishes,
Ivailo
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Chris
Top achievements
Rank 1
answered on 01 Sep 2011, 05:26 PM
Hi Roland,
Did you ever expand upon this solution (i.e. to handle other elements, such as <ul>, colours, etc.)?
We need to get some really clean HTML from the editor (see here) and this may have to be the way forward.
Thanks in advance for any help!
Chris.
Did you ever expand upon this solution (i.e. to handle other elements, such as <ul>, colours, etc.)?
We need to get some really clean HTML from the editor (see here) and this may have to be the way forward.
Thanks in advance for any help!
Chris.