cancel
Showing results for 
Search instead for 
Did you mean: 

Why does the code block syntax highlighting not always work?

Andrew Neil
Evangelist III

I've seen it in a few user posts, and now in this Knowledgebase article:

https://community.st.com/t5/stm32-mcus/porting-and-using-x-cube-eeprom-with-any-stm32/ta-p/570539

AndrewNeil_0-1715705410498.png

 

If I copy that into a code block, I see this:

 

uint16_t address = 0x0001;	// 16-bit virtual address between 0x0001 - 0xFFFE inclusive
  uint32_t data = 0x12345678; // Dummy Data
  status = EE_WriteVariable32bits(address, data);
  if (status != EE_OK)
  {
  	if (status == EE_CLEANUP_REQUIRED)
  	{
  		if (EE_CleanUp() != EE_OK)
  		{
  			Error_Handler();
  		}
  	}

 

 

EDIT:

After posting, that appears like this:

AndrewNeil_0-1715705616353.png

Which is as expected - with line numbers & syntax highlighting.

So what is that thing in the Knowledgebase article? It's also missing the 'copy to clipboard' button!

1 ACCEPTED SOLUTION

Accepted Solutions

You mean he copied it from elsewhere, and the formatting we see in the forum was "inherited" from whatever that source was?

Yes.

Of course, you can achieve the same result by editing the HTML, but not everyone is an HTML professional.

When inserting via </>, you can select the format in the top left-hand corner. You can select HTML, Javascript, CSS, etc., whereby C is preset at the top left.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

9 REPLIES 9
Andrew Neil
Evangelist III

@Andrew Neil wrote:

I've seen it in a few user posts, 


Here's an example:

AndrewNeil_0-1715705980593.png

https://community.st.com/t5/other-hardware/stm32h725-adc/m-p/673791/highlight/true#M27995

 

Again: no line numbers; no syntax highlighting; no 'copy to clipboard'

What's going on?

@hardrock  ?

Laurids_PETERSEN
Community manager
Community manager

Hi @Andrew Neil,

Thanks for catching that on the article, I have fixed the issue and will be looking for other articles with the same issues to correct them.

Regarding the missing line numbering, view more, and copy function: These were added as a customization after we changed the community platform. Some code templates may not have changed retroactively, which is why you may see it in older posts (prior to about July-August 2023). 

With @hardrock's response it's caused by copy-pasting acceptable HTML from another site/editor and not using the standard code template in our text editor. 

Best regards,
Laurids


Peter BENSCH
ST Employee

I am quite sure and have also tested this in parallel that @hardrock, unlike you, did not copy the code block with </>, but simply copied it in directly. Unfortunately, the inserted block then also looks like a source code block. The community team needs to take a closer look at whether this can be made more distinguishable.

As has often been requested, it would also be better to place the </> button right at the beginning of the tool list anyway.

Regards
/Peter

@Lina_DABASINSKAITE 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

@Peter BENSCH wrote:

I am quite sure and have also tested this in parallel that @hardrock, unlike you, did not copy the code block with </>, but simply copied it in directly.  


You mean he copied it from elsewhere, and the formatting we see in the forum was "inherited" from whatever that source was?

That figures.

I find I can also generate a similar-looking block by manually editing the HTML, and just putting in <pre> and </pre> tags; eg,

void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14
                              |RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;

 

I'm really just curious about how this happens - not worried about it as a problem.

 

You mean he copied it from elsewhere, and the formatting we see in the forum was "inherited" from whatever that source was?

Yes.

Of course, you can achieve the same result by editing the HTML, but not everyone is an HTML professional.

When inserting via </>, you can select the format in the top left-hand corner. You can select HTML, Javascript, CSS, etc., whereby C is preset at the top left.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
hardrock
Associate III

Hi everybody,


Sorry my mistake.
I've misunderstood the format of the source insertion.


I've inserted source using by "Preformatted".
From now on, I'll insert source via "</>".


1. Use "Preformatted"

/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();


2. Use "</>"

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

 


@hardrock wrote:

Sorry my mistake.
I've misunderstood the format of the source insertion.


No worries - I was really just curious as to what was going on. Thanks for the explanation.

 


@hardrock wrote:

I've inserted source using by "Preformatted".


What do you mean by that?


@Peter BENSCH wrote:

not everyone is an HTML professional.


Indeed - which is why I'm unimpressed when people say, "just edit the HTML"  as a solution to some of the forum's other shortcomings.

 


@Peter BENSCH wrote:

When inserting via </>, you can select the format in the top left-hand corner. You can select HTML, Javascript, CSS, etc., whereby C is preset at the top left.


Indeed - but no option for just plain text. 

I thought I'd seen a feedback post about that, but can't seem to find it now.

It would be very useful to have the option of plain text.

EDIT:

Example just now:

https://community.st.com/t5/stm32-mcus-boards-and-hardware/hal-rcc-oscconfig/m-p/674455/highlight/true#M19028 


@Andrew Neil wrote:

@hardrock wrote:

I've inserted source using by "Preformatted".


What do you mean by that?


Aha - I've just found it!

AndrewNeil_0-1726578432452.png

So we can do "preformatted" text without having to resort to the Source Code block:

 

ASCII-Art:

+-------------+
| |
------>+ +------>
inputs ------>+ process +------> outputs
------>+ +------>
| |
+-------------+