Home > Default > Inserting blockquote tags into a HTMLDocument

Inserting blockquote tags into a HTMLDocument

November 30Hits:0
Advertisement
G'Day,
I'm having a bit of trouble inserting <blockquote> tags into a HTMLDocument.
Basically I want the blockquote tags to implement an indent feature. ie, you click a button and all the text in the current paragraph gets surrunded by blockquote tags, which when rendered makes it indent.
The code I'm using is:
Element current = doc.getParagraphElement(pos);
try
doc.insertBeforeStart(current, "<blockquote>");
doc.insertAfterEnd(current, "</blockquote>");
catch (Exception e)
lets say we have html like this:
<p>
hello
</p>
when this code runs, i get:
<blockquote>
</blockquote>
<p>
hello
</p>
I think that when I do the insertBeforeStart and insert the opening tag, after that completes the document is rendered and the end tag is put in there automatically???
So, can anyone help me out here and suggest a better way?
Cheers,
Leighton.

Answers

I've been trying to get <blockquote> insert working in an editor but it seems to be a quite difficult task even if it's only about inserting a couple of tags into the right slot! This is the closest I got:
HTMLDocument doc = (HTMLDocument)editor.getDocument();
int start = editor.getCaretPosition()
int paraStart = doc.getParagraphElement(start).getStartOffset();
int paraEnd = doc.getParagraphElement(start).getEndOffset();
String insideBlockQuotes = doc.getText(paraStart, paraEnd - paraStart);
doc.setOuterHTML(doc.getParagraphElement(start),"<blockquote><p>"+insideBlockQuotes+"</p></blockquote>");
This is how it works: Get the current paragraphs start and end positions, read the text between the start and end into a string, replace the paragrapElement with <blockquote><p>..the text from string..</p></blockquote>.
This works 'in about' but it's far from perfect.. it has the following problems:
1. It looses all formatting from the quoted paragraph (bold etc. tags from the quoted part)
2. It assumes that the paragraphElement was a <p> (could have been another element too!)
3. It's ugly
Anybody come up with a better way to use blockquote?

Read other 3 answers

Tags:

Related Articles

  • Inserting blockquote tags into a HTMLDocumentNovember 30

    G'Day, I'm having a bit of trouble inserting <blockquote> tags into a HTMLDocument. Basically I want the blockquote tags to implement an indent feature. ie, you click a button and all the text in the current paragraph gets surrunded by blockquote ta

  • Inserting custom HTML tags into a HTMLDocument to be displayed in a JEditorNovember 30

    Does anyone know how to insert custom tags into a HTMLDocument to be displayed in a JEditorPane? I have tried using the following code, kit.insertHTML( doc,                 jep.getCaretPosition(),                 "<testtag>FFFF</testtag>&

  • Insert BASE tag into HTMLDocument problemNovember 30

    Hi, I've made a prog that read the HTML content from an URL, and write it into a file. But before writing it, I'd like to change the content to add <BASE href="http://www.site.com"></BASE> into the head part of the HTMLDocument. In m

  • Do I need to insert meta tags on domain if it redirects to web.mac page?October 11

    Hi, I've set up a domain (http://www.blossomsolutions.ca) with Internic.ca in Canada and filled out a very easy form to redirect to http://web.mac.com/blossomsolutions. Through this excellent forum I learned how to insert meta tags into all my pages

  • How to insert h1 tags in museNovember 30

    I have tried to insert h1 tags in a muse site and then uploaded. When I come to test the site in SEO Analysis software it says there are no h1 tags! Any ideas? ThanksHi How exactly you are defining the tags ? As Mac_heibu has suggested you can use pa

  • Insert new tags after root elementNovember 30

    Hi, I'm trying to insert new tags immediately after the root element in a DOM tree. The data to be inserted is being passed to the program as a string parameter. I've used Dom4J to add the data as a new element immediatelty after the root. Problem is

  • Insert Div Tag button does nothing. DWCS3November 30

    Using the Insert Div Tag button all of the sudden does not add Div tags to the code view or dotted outline in Design view. Here's the code result from simply creating a new HTML doc, placing my entry point in the after <body>and click the Insert Div

  • Insert HTML.Tag attributes?November 30

    Hey, How would I insert html attributes? I am making a HTML Editor. The following are some valid java html attributes. How would I insert it properly? HTML.Tag.P, HTML.Tag.BLOCKQUOTE, HTML.Tag.CENTER, HTML.Tag.CITE, HTML.Tag.CODE, HTML.Tag.H1, HTML.T

  • Tab inserting blockquoteNovember 30

    I just installed DW on a new laptop and I can't remember where I need to change the setting so that when I am in a list item - I can hit the tab key (or click the indent button) and the current list item becomes a new list under the preceding list it

  • Is there a workaround for inserting form tags?October 11

    Long time ago some developers found some bugs in the SWING class. The bug seems to appear when an HTML page pasted in the browser. Then the <form>-tags are disappeared while they can be found before pasting the HTML into the browser. This is my code

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 0.697 s.