Apply style to first line after n

Asked

Viewed 80 times

1

I have a textarea that had received a text. The style application will be minimal, so I didn’t want to use some editor like Ckeditor, for example. I believe the easiest way to work is to apply a style to the post item /n

I will be receiving a text like the below:

inserir a descrição da imagem aqui

I’d like to keep it that way:

inserir a descrição da imagem aqui

  • What do you think to use to mark the bold style?

  • I will explain a little better. In case the tool is practically an "html generator". As a final process, I will display a code for the user. The markup can be with <Strong> for example...

  • Why not use a WYSIWYG editor that uses HTML tags only?

  • By the way, Ckeditor allows you to configure how the HTML will be generated, for example: http://nightly.ckeditor.com/15-01-26-07-08/full/samples/plugins/htmlwriter/outputhtml.html

1 answer

3


You may be using the CSS ::first-line Selector

Example:

div::first-line {
        font-weight: bold;
    }
    <div>
    Lorem ipsum dolor sit amet,consectetur adipiscing elit. <br />
    Vestibulum erat velit, aliquet at mattis a, tristique ac mauris. <br />
    Quisque et neque quis lectus consequat ornare ut eu augue. <br />
    Praesent sapien massa, <br />
    </div>

    <div>
    Faucibus sed viverra a, ultrices eget velit. <br />
    Aliquam euismod ante eu est tempor posuere. <br />
    Duis semper sodales ligula, et lacinia libero iaculis ac. <br />
    Duis at elementum diam. Sed lectus justo, <br />
    Malesuada eget scelerisque vitae, ullamcorper eget enim. <br />
    Nulla vitae turpis luctus, consectetur velit non, mattis lorem. <br />
    </div>

Supposing the text with the \n, be like this:

    Lorem ipsum dolor sit amet,consectetur adipiscing elit. \n
    Vestibulum erat velit, aliquet at mattis a, tristique ac mauris. \n
    Quisque et neque quis lectus consequat ornare ut eu augue. \n
    Praesent sapien massa, \n \n
    Faucibus sed viverra a, ultrices eget velit.\n
    Aliquam euismod ante eu est tempor posuere. \n
    Duis semper sodales ligula, et lacinia libero iaculis ac.\n
    Duis at elementum diam. Sed lectus justo, \n
    Malesuada eget scelerisque vitae, ullamcorper eget enim.\n
    Nulla vitae turpis luctus, consectetur velit non, mattis lorem.\n

You’ll have to treat the \n.

if(!String.IsNullOrEmpty(texto)){
     texto = texto.Insert(0, "<div>");
     texto = texto.Replace("\n \n", "</div><div>");
     texto = texto.Insert(texto.Length, "</div>");
     texto = texto.Replace("\n", "<br />");
}

Example

  • The problem is that I will be receiving a block of text, coming from my textarea. My text will not be inside a div but below a /n

  • @Rafaelbarbosa, I made an edition

  • It didn’t work by giving replace on two n, but it worked as follows: Description = Description.Replace(System.Environment.Newline + System.Environment.Newline, "</div><div>");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.